No Luck getting Graphics to display

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
Netherfox
Forum Newbie
Posts: 6
Joined: Tue Jan 15, 2008 12:32 pm

No Luck getting Graphics to display

Post by Netherfox »

Hello all,

I am trying to use simple GD functions to accomplish any mundane task such as creating and displaying a rectangle and have had no success. In IE 6, the following code fails continually with "Cannot Create White" when trying to create the white color. In Firefox, it will fail at the same place if the header line is removed, otherwise it gives me the error :"The image “http://localhost/index.php” cannot be displayed, because it contains errors." I am at my wits end here and have been trying to resolve this problem for a number of hours. I have tried upgrading the PHP_GD2.dll file alone, downloading the newest version of php, and messing with all sorts of browser settings and php.ini settings.

Code: Select all

<?php
header('Content-Type: image/png');
$im = ImageCreate(200,200) or die ("Cannot Create Image");
$white = ImageColorAllocate($im,255,255,255) or die ("Cannot Create White");
$black = ImageColorAllocate($im,0,0,0) or die ("Cannot Create Black");
ImageFilledRectangle($im, 50, 50, 150, 150, $black) or die ("Cannot Fill Rectangle");
ImagePNG($im);
?>
Netherfox
Forum Newbie
Posts: 6
Joined: Tue Jan 15, 2008 12:32 pm

Re: No Luck getting Graphics to display

Post by Netherfox »

Solved the problem, yet I don't know what the cause was. The file "index.php" must have been somehow corrupt, because when I typed the same exact code into a new file I was able to display the rectangle. Hope this saves someone else the 6 or so hours :D
Post Reply