NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP GD problems

Andrew Kamm kamm at andrewkamm.com
Thu Jul 13 10:23:35 EDT 2006


On 7/12/06, Jeff Knight wrote:
>
> Try sending the headers at the last possible moment, i.e. just before
> imagepng() so that if you do generate an error, it will display on the
> page, and get rid of that @, you want to know if it is failing.
>
>
> Still having problems -- I tried moving the header(), but it gave me the
'headers already sent' error.

However, having gone back to the original code and removing the '@', my
Linux server did provide a header error and a bunch of goofy characters (the
Windows box still gives "The image "..." cannot be displayed because it has
errors"). Oddly, the header call is the absolute first thing on the script
(and again -- no there's no white space prior to the <?php tag).

Here's what I'm using right now:

<?php
header("Content-type: image/png");
$im = imagecreate(100, 50) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>

Here's what the Linux box is spitting out:

*Warning*: Cannot modify header information - headers already sent by
(output started at /home/.../public_html/test.php:1) in *
/home/.../public_html/test.php* on line *2*
�PNG 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060713/9e7e1538/attachment.html>


More information about the talk mailing list