What are common issues with PHP-generated graphics not displaying correctly in browsers?

Common issues with PHP-generated graphics not displaying correctly in browsers can be due to incorrect headers being sent, leading to the image being interpreted as text instead of an image file. To solve this, make sure to set the correct content-type header for the image being generated.

<?php
header('Content-Type: image/png');
$image = imagecreate(200, 200);
$bg_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 50, 100, 'Hello World', $text_color);
imagepng($image);
imagedestroy($image);
?>