no CAPTCHA image because of corrupted images
| Project: | CAPTCHA |
| Version: | 5.x-3.1 |
| Component: | Image Captcha (image_captcha) |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
my captcha_image module failes to generate the images.
From http://drupal.org/node/205525, i get some code to check imagegd2 module.
<?php
if (function_exists('imagegd2')) {
var_export(gd_info());
}
$fs = array('imagejpeg', 'imagecreatetruecolor', 'imagedestroy',
'imagecolorallocate', 'imagefilledrectangle', 'imagecolorat', 'imagesetpixel',
'imageline', 'imagefontwidth', 'imagettfbbox', 'imagestring', 'imagettftext',
);
foreach($fs as $f) {
print "$f: ". var_export(function_exists($f), TRUE) .'<br />';
}
?>then, the output is
array ( 'GD Version' => 'bundled (2.0.34 compatible)', 'FreeType Support' => true, 'FreeType Linkage' => 'with freetype', 'T1Lib Support' => true, 'GIF Read Support' => true, 'GIF Create Support' => true, 'JPG Support' => true, 'PNG Support' => true, 'WBMP Support' => true, 'XPM Support' => false, 'XBM Support' => true, 'JIS-mapped Japanese Font Support' => false, )imagejpeg: true
imagecreatetruecolor: true
imagedestroy: true
imagecolorallocate: true
imagefilledrectangle: true
imagecolorat: true
imagesetpixel: true
imageline: true
imagefontwidth: true
imagettfbbox: true
imagestring: true
imagettftext: true
seems everything is fine, then what's the problem?
thanks.

#1
Do you get an image on the image CAPTCHA settings page (like in attached screenshot)?
Also, does the math CAPTCHA work, including blocking on wrong answer?
#2
the math captcha works well, but i did not get the pic in the admin either.
#3
Please try the following:
disable line 390 in image_captcha.module (v 5.x-3.1):
<?php// unset the code from $_SESSION to prevent rerendering the CAPTCHA
// unset($_SESSION['image_captcha'][$seed]);
?>
This makes it possible to request the image more than one time, which makes debugging easier
Now go to a form or the admin page where a CAPTCHA image should show up. Try to find out the url of the image, you can do this for example by looking in the html source or right clicking on the image and chose something as "view image" (depending on which browser you use). The url should be something like http://example.com/?q=image_captcha/715730387 .
Load this url by pasting it in the address bar of your browser and report the error message if any.
#4
thansk soxofaan,
i tried, but it still does not work. i tried open the imgage directly like http://example.com/?q=image_captcha/715730387 , then i got an "red cross"(empty image).
i tried image_captcha on another server, still end up with the same problem.
#5
The red cross is with Internet Explorer, I presume? Can you try a different browser (Firefox, opera, ...)?
What happens if you replace that line 390 with
<?phpecho $code;
?>
and again open a CAPTCHA image directly with the URL?
Can you also check your watchdog log (at example.com/?q=admin/logs/watchdog) for (image) CAPTCHA related error messages?
#6
I tried to do
<?php
dpm($code);
?>
in the line 390. it returns me the code genereted by captcha.
i also checked watchdog, there is no error for captcha.
screen shot attached. here.
#7
i tried to download the image file from
http://example.com/?q=image_captcha/715730387
then manually rename it as 715730387.jpg.
the jpg file can be viewed and edited in Photoshop CS, but it cannot be opened in "Windows Picture and Fax viewer".
#8
I don't think there is something wrong with
<?phpdrupal_set_header("Content-type: image/jpeg");
?>
but maybe removing
<?phpdrupal_set_header("Cache-Control: max-age=3600, must-revalidate");
?>
helps for you?
#9
Can you view it in your web browser?
Please attach that file.
#10
it cannot be viewed in broswer (either ie or ff).
file attached.
#11
i guess there is sth wrong with my GD.
#12
I think I found the problem.
If you look at the binary content of that file, you'll see that it starts with four bytes of newlines, before the JPEG data. Most viewers will fail on this.
The reason: you probably have a module or include file in your setup that ends with "?>" followed by two new lines. These new lines are always emitted on every request before any real content.
It is recommended in php to not use a closing "?>" at the end of the file (also see http://drupal.org/node/247058#comment-875378)
The problem is probably in a custom module because Drupal core and most contrib modules don't use a closing "?>".
#13
#14
thanks so much, soxofaan.
i have removed the all the "?>" from all the module files. (suprisely, quite a lot of contrib module got this ending ?>), but the the problem is still there.
anyway, i think the direction you pointed is correct, i am trying to disable the modules one by one to find the root cause.
any other suggestion??
#15
finally, find out the reason. In of my customized module file, i mistakelly added 2 new lines at a beginning.
a BIG lesson for me. thanks soxofaan .
#16
you're welcome
indeed, whitespace before the opening "<?php" is equally evil, but that doesn't happen as often as trailing whitespace after the closing "?>" so I didn't mention it.
#17
Automatically closed -- issue fixed for two weeks with no activity.