The error you're receiving is informing you that you cannot change the response headers to image/png
, because they've already be set and sent. Make sure the header()
line is the very first line in your output. You cannot output anything before it.
As for the second line, imagepng()
, this is used for outputting a portable-network graphic. The $img
variable would be the image resource that would have been built earlier. The following is an extremely basic example using both of these lines:
<?php
// Gets an image resource
$im = imagecreatefrompng("test.png");
// Tells the recipient we're sending image data
header('Content-Type: image/png');
// Output the PNG image data
imagepng($im);
// Cleanup
imagedestroy($im);
?>