Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

php5-gd code only generates image sometimes?

images php coding issues or problems here.

Moderators: macek, egami, gesf

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
<?php
header("content-type:image/png");
$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);
imagepng($im);
imagedestroy($im);
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?
ingram
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Jul 16, 2011 6:13 am

Return to PHP coding => Images

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron