I am trying to display an image from a variable in php. Followed this SO question but i get this instead of image
�PNG IHDRBMyAPLTE����ٟ�IDAT�c��Z8Y]��Ðf�T%����IEND�B
�`
This is my code.
$tt_image = imagecreate( 100, 50 ); /* width, height */
$background = imagecolorallocatealpha( $tt_image, 0, 0, 255, 127 ); /* In RGB colors- (Red, Green, Blue, Transparency ) */
header( "Content-type: image/png" );
imagepng( $tt_image );
imagecolordeallocate( $background );
imagedestroy( $tt_image );
This code is checked and found working. You have to edit your image before displaying. And put header just above displaying image.
$tt_image = imagecreate( 100, 100 ); /* width, height */
$background = imagecolorallocatealpha( $tt_image, 0, 0, 255, 78 ); //fill some color
header ('Content-type: image/png'); //image type header
imagepng($tt_image, NULL, 0); //disply image
imagedestroy($tt_image); //destroy image