Page 1 of 1

[SOLVED] PHP GD library problem

Posted: Tue Oct 12, 2004 10:22 am
by Jean-Yves
Hi,

I am trying to use some GD functions to create an image on the fly. However I keep getting the following error:
The image “http://www.zzzzzzzzzz.com/test2.php” cannot be displayed, because it contains errors.
(zzzzzzzzzz is for illustration purposes only of course!)

At first I thought that it was my dev PC (WinXP, PHP 4.3.4 which makes no mention of the GD library when using phpinfo() )

But on the Linux server running PHP 4.3.9, phpinfo() reports that GD is enabled, as are all sub options, and the version is "bundled (2.0.28 compatible)"

The code is from the tips pdf of the PHPCon2002, by Rasmus Lerdorf:

Code: Select all

<?php
Header("Content-type: image/png");
$im = ImageCreate(630,80);
$blue = ImageColorAllocate($im,0x5B,0x69,0xA6);
$white = ImageColorAllocate($im,255,255,255);
$black = ImageColorAllocate($im,0,0,0);
ImageTTFText($im, 45, 0, 10, 57, $black, "CANDY", $text);
ImageTTFText($im, 45, 0, 6, 54, $white, "CANDY", $text);
ImagePNG($im);
?>
<IMG src="txt.php?text=<?echo urlencode($text)?>">
Any ideas?

Posted: Tue Oct 12, 2004 10:31 am
by twigletmac
Is all that code in one file?

Mac

Posted: Tue Oct 12, 2004 10:33 am
by Jean-Yves
Yes.

I've also tried adding

Code: Select all

$text = "hello" ;
at the top to provide a value for that variable.

Posted: Tue Oct 12, 2004 4:22 pm
by vigge89
of course it doesn't work, you add
<IMG src="txt.php?text=something">
to the image output.
put that in another file and call this script and it should work ;)

Posted: Tue Oct 12, 2004 5:14 pm
by Jean-Yves
Doh!

My brain was in end of workday mode....

Thanks for pointing out my utter muppetness! :D