Page 1 of 1
Captchas Rendering Spam Protector 1.68
Posted: Tue Mar 04, 2008 3:14 pm
by bdconnolly
Dumb question:
I just switched servers. I've got captchas working with Spam Protector 1.68. Here's the deal: My entire site is in grayscale. On the legacy server, I had converted the captchas .png to grayscale. Checked and indeed, those same .pngs are in the plugin folder. BUT on the site, they now render in color.
?
Modern miracle? Should I call a priest?
Brian
Posted: Tue Mar 04, 2008 4:03 pm
by judebert
More likely you need to call a programmer.
I don't know when it happened, but Spam Protector uses GD fonts to render the CAPTCHA. If the functions 'imagettftext' and 'imagejpeg' both exist, then GD will be used (line 711 of version 1.70, from the nightlies).
If GD is used, then the fonts are used and randomly colored.
You could modify the code to fix the problem: right after the "if" statement that checks for GD, copy the lines from the "else". That'll set the CAPTCHA length and tell it to use the .png files instead of the GD image rendering.
Posted: Tue Mar 04, 2008 9:48 pm
by bdconnolly
Tried. Failed. Tried. Failed again. Sorry.
1. could you indulge me and be more specific?
or 2., is it possible to get GD to render the letters in grayscale?
Thanks in advance.
Brian
Posted: Tue Mar 04, 2008 10:58 pm
by judebert
No problem.
I'm using serendipity_event_spamblock 1.70, which you can obtain from the latest nightlies. Unarchive it and upload the files
except your grayscale PNG files to the Serendipity plugins/serendipity_event_spamblock/ directory.
Edit serendipity_event_spamblock.php. On line 711, you should see:
Code: Select all
if (function_exists('imagettftext') && function_exists('imagejpeg')) {
$max_char = 5;
$min_char = 3;
$use_gd = true;
} else {
$max_char = $min_char = 5;
$use_gd = false;
}
Immediately afterward, on line 719, insert this code:
Code: Select all
$max_char = $min_char = 5;
$use_gd = false;
Your site should now use the PNG files to render the letters (on line 1181, the if will fail; instead the else on line 1234 will run, loading the captcha_
char.png files).
Oh, crap. I just found out why it didn't work.
Go to line 654 of your already-modified file. There you'll see:
Code: Select all
if ($use_gd || (function_exists('imagettftext') && function_exists('imagejpeg'))) {
$max_char = 5;
$min_char = 3;
$use_gd = true;
} else {
$max_char = $min_char = 5;
$use_gd = false;
}
You see it's
checking again, resetting the change we just made. Change the if to simply:
If these changes don't help, let me know what's going wrong and I'll help figure it out.
Posted: Tue Mar 04, 2008 11:02 pm
by judebert
You can also get GD to render in grayscale. Just find all the calls to imagecolorallocate(). They take four arguments: an image and R, G, and B components.
Make sure that the R, G, and B always match. Something like:
Code: Select all
$gs = mt_rand(50,235);
$color = imagecolorallocate($image, $gs, $gs, $gs);
Posted: Wed Mar 05, 2008 3:15 am
by bdconnolly
Couldn't get the png to dance for me. But the RGB worked perfectly!
Thanks Judebert.
Posted: Wed Mar 05, 2008 3:07 pm
by judebert
Glad something worked out!