Trouble rendering GD image creation

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
black_hat
Forum Newbie
Posts: 9
Joined: Thu Sep 10, 2009 4:48 am
Location: Los Angeles

Trouble rendering GD image creation

Post by black_hat »

I have the latest version of WAMP installed with the following enabled in php.ini

extension=php_gd2.dll

gd.jpeg_ignore_warning = 0

but when I test

Code: Select all

 
header("Content-type: image/png");
$im = @imagecreate(110, 20)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
 
I get

Code: Select all

?PNG  ??? IHDR???n??????V,????PLTE????[an????fIDAT?c`?`fx???`?????41???????q?@?;{á0? ?i
Any ideas or further changes to the ini? Thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Trouble rendering GD image creation

Post by jackpf »

what do you get if you comment out the "header('Content-Type...." line?

Any errors or anything? If not, try putting:

Code: Select all

ini_set('display_errors', E_ALL);
error_reporting(E_ALL);
at the top of the script.

It looks like the browser is trying to display the binary..
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Trouble rendering GD image creation

Post by Ollie Saunders »

This is probably a headers already sent error. Only you're not seeing the errors because they are disabled. If you do what jackpf suggests you should see a header already sent error. Google will tell you how to fix those quite effortlessly.
User avatar
black_hat
Forum Newbie
Posts: 9
Joined: Thu Sep 10, 2009 4:48 am
Location: Los Angeles

Re: Trouble rendering GD image creation

Post by black_hat »

Well I tried error logging with no result. I've since moved over to the Google graphing API and works for my requirements. As always, thank you for your prompt replies and insightful posts. Cheers,
Post Reply