no CAPTCHA image because of corrupted images

gnosis.kv - June 18, 2008 - 08:26
Project:CAPTCHA
Version:5.x-3.1
Component:Image Captcha (image_captcha)
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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

soxofaan - June 18, 2008 - 08:53

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?

AttachmentSize
Picture 1.png114.82 KB

#2

gnosis.kv - June 18, 2008 - 17:08

the math captcha works well, but i did not get the pic in the admin either.

#3

soxofaan - June 18, 2008 - 21:08

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

gnosis.kv - June 20, 2008 - 02:48

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

soxofaan - June 20, 2008 - 07:07

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

<?php
echo $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

gnosis.kv - June 20, 2008 - 07:26

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.

AttachmentSize
2008-06-20_152011.png15.47 KB

#7

gnosis.kv - June 20, 2008 - 07:58

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

soxofaan - June 20, 2008 - 08:03

I don't think there is something wrong with

<?php
    drupal_set_header
("Content-type: image/jpeg");
?>

but maybe removing

<?php
     drupal_set_header
("Cache-Control: max-age=3600, must-revalidate");
?>

helps for you?

#9

soxofaan - June 20, 2008 - 08:06

the jpg file can be viewed and edited in Photoshop CS, but it cannot be opened in "Windows Picture and Fax viewer".

Can you view it in your web browser?
Please attach that file.

#10

gnosis.kv - June 20, 2008 - 08:12

it cannot be viewed in broswer (either ie or ff).

file attached.

AttachmentSize
677687229.jpg5.73 KB

#11

gnosis.kv - June 20, 2008 - 08:27

i guess there is sth wrong with my GD.

#12

soxofaan - June 20, 2008 - 08:28
Status:active» fixed

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

soxofaan - June 20, 2008 - 08:55
Title:Captcha_image fails to generate the images.» corrupted images with image CAPTCHA

#14

gnosis.kv - June 20, 2008 - 10:02

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

gnosis.kv - June 20, 2008 - 10:12

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

soxofaan - June 20, 2008 - 10:17
Title:corrupted images with image CAPTCHA» no CAPTCHA image because of corrupted images

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

Anonymous (not verified) - July 4, 2008 - 10:24
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.