[nycphp-talk] PHP GD problems
Dan Cech
dcech at phpwerx.net
Thu Jul 13 11:08:36 EDT 2006
Ken Robinson wrote:
> At 10:23 AM 7/13/2006, Andrew Kamm wrote:
>> 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
This little snippet is a dead giveaway that the file in question is
encoded with UTF-8 including the Unicode BOM.
Therefore, PHP sees line 1 as:
<?php
and begins the output at line 1. Remove the Unicode BOM and you'll be fine.
That said, closing PHP tags at the end of your files can also cause
these kinds of headaches, which is why I prefer to end all my php files
with the following:
// end of script
followed by a single newline
Dan
More information about the talk
mailing list