php5-gd code only generates image sometimes?

images php coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sat Jul 16, 2011 6:13 am

php5-gd code only generates image sometimes?

Postby ingram » Sat Jul 16, 2011 6:22 am

When using this code, which generates a square image with a random color, the image will only display in my browsers about 30% of the time. The other 70%, I get a message like this in FireFox:
"The image “http://localhost/test2.php” cannot be displayed, because it contains errors."
and I get a blank page in Chrome.

Code: Select all

$im = imagecreate(100, 100);
$a = sprintf('%04x',mt_rand(0, 65535));
$b = sprintf('%04x',mt_rand(0, 65535));
$c = sprintf('%04x',mt_rand(0, 65535));
$white = imagecolorallocate($im,$a,$b,$c);
echo "\n\n\n$a-$b-$c";

I'm using LAMP on Ubuntu 10.10. I tested the same code on a different web server and it works fine. Any idea why it would only generate the image sometimes?

Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest