I am able to run this in PHP 5.4.10 without issue. And viewable as a PNG:
What version of PHP are you using? Are you sure the GD library is installed? Open up a PHP file & place this phpinfo
command at the top of it to see if GD is loaded:
<?php
phpinfo();
?>
That said, I did notice an odd error in PHP 5.2.17 which I can switch to in my MAMP setup: Even if I have the command die();
after your code, the page bombs out. Something is different in the PHP parser between PHP 5.4.10 and PHP 5.2.17 it seems. But that is just me. Unclear what your setup is like.
EDIT I think I figured out the issue. Some browsers are case sensitive to headers. So change this:
//output image
Header('Content-type: image/png');
imagepng($im);
To this:
//output image
header('Content-Type: image/png');
imagepng($im);
Note the capital T
in Content-Type
in my edit. Try that out.