Commit 4faee44f authored by Arnab Nandi's avatar Arnab Nandi

added function checks for people with GD problems.

parent cdb9128c
......@@ -5,11 +5,9 @@ Enable the module, and then go to admin/settings/captcha to enable captchas for
Notes:
- Uses GD to draw stuff, emits in PNG
- Captcha for comments is contingent upon a patch(#14708) for now.
Captcha Todo:
- clean up image generation code.
- make captcha distortion more spiffy.
- Captcha for comments is contingent upon a patch(#14708) for now. One day, this will reach core.
- I've added function_exists checks for it to degrade gracefully across multiple versions of GD,
please file issues with the exact GD, PHP information if you have problems.
Captcha Demo:
http://arnab.drupaldevs.org
......@@ -236,7 +236,6 @@ function _captcha_image() {
// creates two variables to store color
$background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
$foreground = imagecolorallocate($im, rand(0, 80), rand(0, 80), rand(0, 80));
$middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160));
// fill image with bgcolor
imagefill($im, 0, 0, $background);
......@@ -296,15 +295,18 @@ function _captcha_image() {
imagedestroy($im);
$im = $im2;
}
$middleground = imagecolorallocatealpha($im, rand(160, 200), rand(160, 200), rand(160, 200), 80);
// random shapes
for ($x=0; $x<50;$x++) {
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
// add cloud only if function is defined (many PHP installations have this function missing)
if (function_exists('imagecolorallocatealpha')) {
$middleground = imagecolorallocatealpha($im, rand(160, 200), rand(160, 200), rand(160, 200), 80);
// random shapes
for ($x=0; $x<50;$x++) {
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
}
}
//output to browser
imagepng($im);
imagedestroy($im);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment