Captchas Rendering Spam Protector 1.68

Creating and modifying plugins.
Post Reply
bdconnolly
Regular
Posts: 140
Joined: Tue Apr 04, 2006 9:37 pm

Captchas Rendering Spam Protector 1.68

Post 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
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
bdconnolly
Regular
Posts: 140
Joined: Tue Apr 04, 2006 9:37 pm

Post 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
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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:

Code: Select all

        if ($use_gd) {
If these changes don't help, let me know what's going wrong and I'll help figure it out.
Judebert
---
Website | Wishlist | PayPal
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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);
Judebert
---
Website | Wishlist | PayPal
bdconnolly
Regular
Posts: 140
Joined: Tue Apr 04, 2006 9:37 pm

Post by bdconnolly »

Couldn't get the png to dance for me. But the RGB worked perfectly!

Thanks Judebert.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Glad something worked out!
Judebert
---
Website | Wishlist | PayPal
Post Reply