I was trying to run an example given in a book that produces a PNG image on the page:
<?php
//set up image
$height = 200;
$width = 200;
$im = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 0, 0, 255);
//draw on image
imagefill($im, 0, 0, $blue);
imageline($im, 0, 0, $width, $height, $white);
imagestring($im, 4, 50, 150, 'Sales', $white);
//output image
Header('Content-type: image/png');
imagepng($im);
//clean up
imagedestroy($im);
?>
The problem is that when I run it, all I get is a broken image icon. Firefox additionally tells me that the image can't be displayed because it contains error. What am I doing wrong?