Closed (fixed)
Project:
CAPTCHA
Version:
6.x-2.x-dev
Component:
Image Captcha (image_captcha)
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Sep 2009 at 14:02 UTC
Updated:
11 Oct 2009 at 17:50 UTC
Jump to comment: Most recent file
Comments
Comment #1
soxofaan commentedThis is certainly possible, however not implemented :)
using PNG instead of JPG requires a two line change in image_captcha.user.inc (around line 33):
(The choice between PNG and JPEG is pretty arbitrary, but a reason I chose JPEG is because it gives some extra noise and artifacts, which makes automatic character recognition slightly harder.)
Having a transparent background would involve some more changes however (mainly an appropriate call to
imagecolortransparent()in_image_captcha_generate_image(). I don't have time to implement this for the moment, but I welcome patches :)Comment #2
machi27 commentedthanks for answering so quick.
I have done the first part, setting the image a png, worked perfect,
But i am stuck with calling
imagecolortransparent(),I never used this before so i had to read a litle, after placing
imagecolortransparent($image, $background_color);on line 92 nothing really happens,i tried to define a color to be replace with the trans, in that case i get a black background.
any suggestion?
Comment #3
machi27 commentedFinally made it, it is working if Distortion level<=1.
I feel like an idiot, I shoud it try to disable the distorsion before, I spent to much time searching for info and it was done at the first try, so i gues that i have to get a bit deper with the function that control the distorsion.
I think that after solving (if i solved it) this issue adding the posibility to the module to choose between jpg or png and giving the option to use a transparent background would be great.
Comment #4
machi27 commentedsoxofaan,
I have been working on the patch, and i would like to ask you few things.
- i have added a select list where user can select what image type you wish, jpg png... working great
- about the transparent background it is working as long there is no distorsion, i am still working on that.
I would like to know what do you think about which is the best option,
1. get ready of the image type selector, i guess that as long an user doesnt want a transparent background image there is no need for a png image, add instead a checkbox to give the option for a transparent image and in case is TRUE, create png, FALSE crate jpg???
2. leave the type image select and add a checkbox to select or not background's transparency???
I am having troubles to make the transparency work as long as distorsion is higher than 1, have you ever tried to do this and leave it because you found it is imposible???
Thanks
Comment #5
soxofaan commentedHi machi27,
Thanks for your work and don't be afraid to post unfinished patches (as long as you mark them as such).
That way I can give you more feedback earlier.
Regarding the file type selection:
I think we should also have a look at file sizes (I don't have access to my Drupal development environment for the moment, so I can't test this now), but I guess the average file size of the JPGs will be smaller than the PNGs (especially if distortion and noise are enabled).
In this regard: PNG only has added value when transparency is desired.
In any case: I would avoid checkboxes, because they would make things more complicated UI-wise than needed.
I would use a select list (or radio buttons) with options:
* JPEG
* PNG with transparent background
If required/desired/requested, we then can always add an option
* PNG (without transparent background)
without much problem.
about your problem with transparency and distortion: please post your unfinished patch, so I can have a look
Comment #6
machi27 commentedHi soxofaan,
I agree with you, I just finish those modifications, so now we have a select list with the mentioned options,
transparency it's working with all the other noise options (salt & peper and lines) in any range.
but still not working with distorsion > 1. :(
It didnt take me to much time, it was pretty easy and I used a pretty basic solution, maybe you found the script to basic... I was still trying to found a solution for the dist/trans issue, but i guess that as you said it is gonna be better and faster to upload the patch with the transparency(distorsion bug.
I need to download somethings and make the patch, will upload asap.
Comment #7
machi27 commentedHI soxofaan,
I think that i havent done good the patch, it looks a bit weird and long to me, I use the tortoise cvs for windows, also tried the cygwin but it was even worst.
i think i am missing something in the patch settings coz it is adding to many lines and headers doesnt look like in a normal patch.
anyway i am gonna uploaded to let you see it.
Still working with the transparency/distortion bug...
Comment #8
soxofaan commentedIndeed, the patch is not ok.
I don't use windows, so I can't help you with tortoise.
You should find more info at
http://drupal.org/patch
or more specifically at http://drupal.org/node/113172
If you keep struggling, you could also just post the files you changed, but I would prefer a patch.
There have also been some updates since you checked out the version you are working on
so you should run "cvs update".
thanks
Comment #9
machi27 commentedi have updated the cvs, and version that i am using is the last dev, downloaded today.
I knew that the patch was wrong,
And yea i was using those pages as refer, gonna give another try.
hope i can make it this time
Comment #10
machi27 commented***************** forget about this, SORRY!!!! **************************
i hope i am not making you waste your time
Comment #11
machi27 commented*************** sorry u can forget about this too *******************
I am sorry i was checking i think that i understand now what you mean saying that i wasnt working with the last version, i hope now i did, i am not very sure yet about the patch, i made it by cygwin, with the diif -up, looks better than before but stills a bit weird. I also uploaded a zip with image_captcha.user.in and image_captcha.admin.inc
Hope didnt make you waste your time,
Comment #12
machi27 commentedHi soxofaan,
finally WORKS!!!!!! :))
I think that the last modications that you made helped a lot, (working with the last cvs), I guess that maybe my final code still a bit dirty even after cleanning it.
I notice that to render a png transparent background best quality "background color must be set to #FFF", with background = #000, letters are a bit mess. so shouild I add in background color description a litle note???
I checked with all distorsion and noise posibilities, and it is working good for me.
I dont understand why at the end it have been soo easy to make it work, I am using the first code that i wrote but it didnt work first time???
So i guess that you should forget about my latest post and whenever you have time could please check the NEW files, I am not very good making a patch but i am gonna try again.
Thanks and hope didnt make you waste your time...
Comment #13
machi27 commentedsoxofaan,
Here we go, I hope patch is ok this time,
also upload the files in case my patch is not good.
pls let me know.
Thanks
Comment #14
machi27 commentedsorry, something weird happened and didnt uploaded the patches, here we go
Comment #15
soxofaan commentedHi Machi27, apparently you've been busy working on this ;)
Some feedback:
and then use these constants instead of hardcoded values.
variable_get('image_captcha_type_img', 'jpg')this is wrong: the first argument should be the variable name, which is 'image_captcha_image_format' and the second should be the key of the options array (e.g. the constant IMAGE_CAPTCHA_FILE_FORMAT_JPG I defined higher)$img_type = variable_get('image_captcha_image_format');this is also wrong, the first argument is ok, but there should be a second argument tooThis may look like a lot, but I guess this is one of your first Drupal patches (or maybe your first), and it takes some time before you get all those small details.
So no problem, I hope you've learned some things.
thanks for your work
Comment #16
machi27 commentedYep you are right, I have done many personal modifications but never a real patch before, and yea i am learning a lot about all this things. which is the main goal...
Zendstudio, gonna take a look to see if there is as option to do that, hope it does. I am using cygwin to make the patch, tortoise to download the last cvs . I am not sure about how to make "diff -up" with all the files that i want to compare.
Newbie mistake modifying the $Id... sorry
I understand and agree with all the other things.
I have done all those changes and carefully looked at the code standards, hope not missing anything.
Comment #17
soxofaan commentedCheck if your version of diff under Cygwin has the option
--strip-trailing-cr, maybe that will avoid the end of line problems. And you just have to list the files you want to create a patch for (if you don't specify files, diff will take all files that differ. So the following command should do it, I think:diff -upw --strip-trailing-cr image_captcha.module image_captcha.admin.inc image_captcha.user.inc > pngtransparency.patch(note the "-w" option is for ignoring changes in whitespace, which is often a good idea to add)
And again: no problem with the newbie mistakes, we've all been newbies. I hope you enjoy hacking Drupal.
Comment #18
machi27 commentedI enjoyed to much, :)
Ok this is what i finally get, I made all those changes, and i think code looks a bit cleaner.
I found the option in zend to use end lines as linux.
I am not sure if this is the final result but we are getting closer, maybe i missed something or the patch is not clean enough...
Comment #19
soxofaan commentedGetting closer indeed.
I think you missed some spots to replace the hardcoded values to the constants
e.g. in several cases of
variable_get('image_captcha_image_format', 1)and in the option list of the select widget. There are also some places where there are tabs instead of spaces for indentation.Some UI strings need some rewording too.
I worked a bit on the patch and changed these small things myself.
be welcome to try it out
Comment #20
machi27 commentedouch, i guess all this mistake are the different between a noob an a pro which i am far of it
i was comparing bolth files, damm it dont understand who could i miss e.g
$img_type = variable_get('image_captcha_image_format', 1);, I should give it a bit more of time before posting it, just making sure about those things, about the tabs/space issue dont know what to say... :(. About the widget i was confuse, wasn't sure and tried to respect the way you defined the other widgets, but now i understand my mistake. :)I notice a few changes and i am wonder if you could please explain.
*/ image_captcha.user.inc, I define
drupal_set_header("Cache-Control: max-age=3600, must-revalidate");in the if and in the else, but you only defined in the if. should it be define in both???/* image_captcha.user.inc, i define
$img_typetwice, one forIMAGE_CAPTCHA_FILE_FORMAT_JPGand them redifine it forIMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG, but you define$img_typeand$file_format, I guess (please correct if I am wrong) it must be done your way for avoiding mixing vars???*/ concerning the "patch making" and the "end of lines" issue, was it ok that way?
what do you mean with
, e.g. changing
image_captcha_color_settings???I can only say thanks a lot, I am learning a lot trying to make a patch, i am a bit dissapointment because i couldn't make it perfect.
Comment #21
soxofaan commentedHi,
no need to despair, you are doing fine ;)
I just wanted to tweak some small things that would be easier to do in the code than posting them here as a comment.
Anyway, about your questions:
drupal_set_header("Cache-Control: max-age=3600, must-revalidate");was code for the 6.x-1.x branch that was no needed anymore, so I removed it all together.$img_typeand$file_formatyou are right, I mixed some stuff. I wanted to harmonize the names of the constants (IMAGE_CAPTCHA_FILE_FORMAT_JPG), the drupal variable (image_captcha_file_format) and the local variables (file_format), but I forgot to change one case of "img_type". I prefer "file_format" over "img_format" (which could also refer to the image size) and "img_type" (which could also refer to color/grayscale settings). Patch in attachment should be better.I removed the
[br/], because it's best to avoid unnecessary markup and your sentence about PNG-transparency didn't look right grammatically. I changed it toAnother thing I tweaked was putting "JPEG" and "PNG" in
t()(not really important) and also changed from "PNG - transparent background" to "PNG with transparent background" because the minus/dash in your version could be interpreted as "without". Another thing I did, was putting the file format option at the end of the "color and image settings" fieldset, because it is typically the least important.I hope this gives you more insight in my changes.
Thanks anyway for your work
Comment #22
soxofaan commentedreally annoying that previewing comments doesn't work #580564: Comment preview doesn't work anymore, I have to edit my post several times and then forget to attach the patch.
So here it is ;)
Comment #23
soxofaan commentedOk, forget previous patch
this one should be more readable/understandable
Comment #24
machi27 commentedhi!!!
So... did we/YOU finnally make it??? i have tested and it is working great.
I am sorry that at the end you had to spent some time doing this... but I am glad that as result your captcha module have improve even if no one use the transparency background.
I will definetly use it.
Thanks a lot for everything
Comment #25
soxofaan commentedyep, I committed the patch:
http://drupal.org/cvs?commit=266448
congratulations and thanks for your work and review.
There is still some follow up work to do:
now the GD-library is only checked for JPG-support (see e.g. #580364: Image CAPTCHA reports no GD, Drupal status report disagrees), I think checking for PNG support should be added too.
Comment #26
machi27 commentedI am not sure if is this what we needed, maybe I forgot to touch another file, I have tried and it is working as before, but as I have those GD-lib I dont get any error.
Please let me know if it is OK, (patch is ok?)
Had special care about the tab and space and the end of lines as linux.
BTW i saw that you have introduced new fonts, none worked for me :(, but with my old font everything was perfect.
********forget about this patch, check the nextone********
Comment #27
machi27 commentedI am sorry I noticed after uploading i made a mistake not very important but in this file is solved
Comment #28
machi27 commentedI realize that with this changes the script is checking both JPEG and PNG and display an error message no matter what format is used.
Do you think that it will be better to make the script to first check the image format and depending selected format check if current lib is ok???
Comment #29
soxofaan commentedI think now with the addition of PNG support, things get more complicated.
But I think it's a bit out of the scope of this issue thread, so I decided to start a new one for this: #589388: refactor _image_captcha_check_setup() for GD/JPEG/PNG support and set this thread to fixed.
Thanks anyway