I took code from the php.net
function LoadPNG($imgname)
{
$im = @imagecreatefrompng($imgname);
if(!$im)
{
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/png');
$path = './upload/xxx.png';
$img = LoadPNG($path);
imagepng($img);
imagedestroy($img);
and I have message in browser and page doesn't load:
No data received Unable to load the webpage because the server sent no data. Here are some suggestions: Reload this webpage later. Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
But if I change imagecreatefrompng to imagecreatefromjpeg, imagepng to imagejpeg and path to jpeg file. Or write incorect file I have error image (imagestring) - it works fine...
This sounds like a memory issue. I would change this line
$im = @imagecreatefrompng($imgname);
to this
$im = imagecreatefrompng($imgname);
You may get some more information if you do that. Just change it back when you put this code into production. Your users do not need to see any warnings and errors. If it is a memory issue, that same section where you got the code has this tidbit of information.
See there - http://forums.freebsd.org/showthread.php?t=21542