PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Text » Text_CAPTCHA » Bug #4133

Returns empty image

Details

Submitted2005-04-12 22:50 UTC
Fromjeff at jweinberger dot homeip dot net
StatusBogus
PackageText_CAPTCHA
PHP Version5.0.3
OSMac OS/X 10.3.8 with Apache 1.3
Roadmaps(Not assigned)

Comments

[2005-04-12 22:50 UTC] jeff at jweinberger dot homeip dot net

Description:
------------
Using the sample code provided, I created a simple test
to just create a CAPTCHA and display the image and the
phrase. The phrase returns correctly, but the image
returns empty.

In the code sample provided, $c (the instance of the
CAPTCHA) contains an object, but $im (the returned
image) is empty. The file (test.png) is successfully
written, but contains zero (0) bytes.

This same symptom occurred using the GetCAPTCHAAsJPEG()
and GetCAPTCHA().

I also examined $php_errormsg and it contains a warning
about 'var declarations' being deprecated.

I have checked to be certain that the "require"d files
(image/text.php, text/password.php, text/captcha/
drivers/image.php and pear.php) all exist and are
successfully included.

Please feel free to e-mail me with any questions.

Thank you for your help!

Reproduce code:
---------------
<?php
require_once 'Text/CAPTCHA.php';
$c = Text_CAPTCHA::factory('Image');
$options = array();
$options['font_size'] = '24';
$options['font_path'] = '/library/fonts/';
$options['font_file'] = 'ArialHB.ttf';
$c->init(200, 80, NULL, $options);
$phrase = $c->getPhrase();
$im = $c->getCAPTCHAAsPNG();
file_put_contents('test.png', $im);
print '<img src="test.png">';
print '<br>';
print $phrase;
?>

Expected result:
----------------
When the script is called from a browser, this script
should display the CAPTCHA image then on the next line,
the CAPTCHA phrase.

Actual result:
--------------
The Script displays a "broken image" icon and on the
next line successfully shows the CAPTCHA phrase

[2005-04-13 16:02 UTC] jeff at jweinberger dot homeip dot net

I tried this also without specifying a font file as:
$c->init(200,80);
with the same result. I also tried with several other
font files (suspecting font corruption might be a
problem).
I also ran a simple test creating a PNG image and
displaying it, saving it to a file and displaying that
file, which all worked (suspecting that GD might be the
issue).

The resulting image file that is written is neither
corrupted nor does it contain an error message. I've
opened it with various text-editors and resource tools,
and the file is in fact empty (contains zero bytes).

I'm certain that this works fine under some/many/most
configurations, but for some reason does not for me.

Is there anyway you can suggest that I can test within
the Text_CAPTCHA package to see where it might be
failing, and if the problem points to some sort of
configuration issue on my server? (I am still relatively
new to PHP, and am not that famiiar with the object
model, so I want to make sure that any diagnostics I use
won't in themselves cause more problems).

So, I'm still a bit bafffled.

Thank you for your prompt response and for your help.

--Jeff

[2005-04-14 17:23 UTC] jeff at jweinberger dot homeip dot net

Thank you for your help and support. The idea of
checking the fonts was a good one. I don't think it's
the problem, though. But, here's what I tested, and the
results:

First I checked GD_Info and FreeType support is enabled
(that's the only font information given).

Then I created an image and used imagestring with a
default font (I tried each ID 1-5) and all succesfully
created, saved and displayed the image.

Then I looked at the Text_CAPTCHA code and the
Image_Text code on which it depends, and saw that it was
using imagettftext to write the text onto the image.

So I created with imagettftext to do the same thing. I
tested about 10 different fonts of different types. in
my test my .ttf fonts worked but did not render
properly. So I tried several others. All the other fonts
on my system rendered perfectly, and worked in my test.

I then went back to my Text_CAPTCHA test script and ran
it without the $options included in the init ($c-
>init(200,80); ) It failed as before.

I then included the $options array again, and this time
tried with five of the fonts that had successfully
rendered properly in my test above.

In all five cases, whether I displayed the image or
wrote it to a file and then displayed it, Text_CAPTCHA
failed exactly as described in my first post.

Is there another test I can try to be sure I have not
missed anything? or is there something in this
information that might point to the problem?

Thank you very much once again for your help and
support.

[2005-04-18 17:36 UTC] jeff at jweinberger dot homeip dot net

Thank you again for your time and your help.

However, now I feel like a bit of an idiot for not
considering the packages on which Text_CAPTCHA is
dependent.

It seems now that the problem is in fact in Image_Text.

I used the sample code provided with Image_Text and
changed only the fonts to those which I know worked well
in my previous tests.

Image_Text returned an empty image.

So, I have to conclude that Text_CAPTCHA is working
properly, and passing along the (empty) image returned
by Image_Text.

I will report this to Image_Text and go from there.

Thank you again for your help.

--Jeff