PEAR is archived and read-only

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

Home » Images » Image_Text » Bug #4178

Image_Text returns empt image

Details

Submitted2005-04-18 18:06 UTC
Fromjeff at jweinberger dot homeip dot net
StatusBogus
PackageImage_Text
PHP Version5.0.3
OSMac OS/X 10.3.8
Roadmaps(Not assigned)

Comments

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

Description:
------------
Hi:

This report comes from an attempt to use Text_CAPTCHA,
which in turn uses Image_Text to create its image. When
Text_CAPTCHA returned an empty (zero bytes) image, I
reported that bug, and eventualy discovered that
Image_Text was actually returning an empty (zero bytes)
image.

I tested this as follows:

I ensured that the GD library is working. I am able to
create an image, display it, save it to a file, and then
display that file. I tested this with GIF, JPEG and PNG
images.

I then tested my ability to add text to an image by
using both imagestring and imagettftext (the latter I
notice is what you use) and with a variety of fonts of
different types.

Choosing three fonts that worked well with imagettftext,
I then tried the sample code distributed wit Image_Text.

The image returned was empty. If I tried to save it to a
file, it would successfully create the file, but the
file size is zero bytes. If I simply displayed the
image, nothing displayed, and my browser showed no
"source" for the page.

The code is the sample code provided with Image_Text,
but I have included it here for your reference.

I do not know where to look further to see how I can get
this to work or if there is a problem with the code that
needs to be fixed.

Please also let me know if there are things I should
test to help isolate the issue.

Thank you very much for your help on this.

--Jeff

Reproduce code:
---------------
<?php
// This is a simple example script, showing Image_Text's facilities.
require_once 'Image/Text.php';
$colors = array(
0 => '#0d54e2',
1 => '#e8ce7a',
2 => '#7ae8ad'
);
$text = "EXTERIOR: DAGOBAH -- DAY\nWith Yoda\nstrapped to\n\nhis back, Luke climbs up one of the many thick vines that grow in the swamp until he reaches the Dagobah statistics lab. Panting heavily, he continues his exercises -- grepping, installing new packages, logging in as root, and writing replacements for two-year-old shell scripts in PHP.\nYODA: Code! Yes. A programmer's strength flows from code maintainability. But beware of Perl. Terse syntax... more than one way to do it... default variables. The dark side of code maintainability are they. Easily they flow, quick to join you when code you write. If once you start down the dark path, forever will it dominate your destiny, consume you it will.\nLUKE: Is Perl better than PHP?\nYODA: No... no... no. Orderless, dirtier, more seductive.\nLUKE: But how will I know why PHP is better than Perl?\nYODA: You will know. When your code you try to read six months from now...";
$options = array(
'canvas' => array('width'=> 600,'height'=> 600), // Generate a new image 600x600 pixel
'cx' => 300, // Set center to the middle of the canvas
'cy' => 300,
'width' => 300, // Set text box size
'height' => 300,
'line_spacing' => 1, // Normal linespacing
'angle' => 45, // Text rotated by 45?
'color' => $colors, // Predefined colors
'max_lines' => 100, // Maximum lines to render
'min_font_size' => 2, // Minimal/Maximal font size (for automeasurize)
'max_font_size' => 50,
'font_path' => '/Library/Fonts/', // Settings for the font file
'font_file' => 'Arial',
'antialias' => true, // Antialiase font rendering
'halign' => IMAGE_TEXT_ALIGN_RIGHT, // Alignment to the right and middle
'valign' => IMAGE_TEXT_ALIGN_MIDDLE
);
// Generate a new Image_Text object
$itext = new Image_Text($text, $options);
// Initialize and check the settings
$itext->init();
// Automatically determine optimal font size
$itext->autoMeasurize();
// Render the image
$itext->render();
// Display it
$itext->display();
?>

Expected result:
----------------
Image containing the text

Actual result:
--------------
a zero byte image

[2005-08-25 01:14 UTC] jager at tne dot net dot au

Hi there.

I also had issues with OS X (10.4.1) in using the
Text_CAPTCHA class, and narrowed it down as well to an issue
with Image_Text. Anyway, after a bit of stuffing about, I
got it to work. It require me to install a new version of
php that had better GD integration. Before I had Marc
Liyanage's PHP with GD from his entorpy website, and the
regular Apache that comes in OS X.

I was using PEAR as portable lbraroies and manually
installing. When I tried to install Image_Text using pear
installer, it complained the GD php extension was not
installed!!!

...Long winded work around...

So I installed "Complete PHP" (do a google search for it).
This requires its partner issue called "Complete Apache",
which installs Apache 2. It wont replace your old PHP or
Apache, so you can go back anytime. You will need to turn
off websharing in OS X, and "Complete Apache" will let you
install its own preference pane, that is more featured to
control the server. You have to relocate your website files
into a different folder than the typical ~/Sites folder.
This is in a new folder created by the installer called /
Library/Apache2/htdocs/

It is all explained simply in the install documentation! And
even better, Image_Text works perfectly now.. sweet!!! I
spent many hours trying to figure out why Image_Text wasnt
working!! Most frustrating.

Paul