[SOLVED] PHP GD library problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

[SOLVED] PHP GD library problem

Post 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?
Last edited by Jean-Yves on Tue Oct 12, 2004 5:14 pm, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Is all that code in one file?

Mac
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post by Jean-Yves »

Yes.

I've also tried adding

Code: Select all

$text = "hello" ;
at the top to provide a value for that variable.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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 ;)
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post by Jean-Yves »

Doh!

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

Thanks for pointing out my utter muppetness! :D
Post Reply