I am trying to make this .php file act as a .png, so I can do e.g. <img src='test.php'> [example]
I added a header as an image and did this:
<?php
/* Start Connection */
[Ignore This]
/* End Connection */
/* Add to counter */
mysql_query("UPDATE counter SET counter = counter + 1");
/* End Add */
/* For Echo */
$count = mysql_fetch_row(mysql_query("SELECT counter FROM counter"));
$hits = $count[0];
/* Create Echo as Null
* @echo
echo "$hits";
*/
/* End Echo */
//Img Area
$font = "font.ttf";
$image = imagecreatefrompng("hits.png");
$color = imagecolorallocate($image, 255, 255, 255);
imagettftext($image, 15, 0, 10, 24, $color, $font, $hits);
imagepng($image, "test.png");
imagedestroy($image);
header('Content-Type: image/png')
?>
But it just displays a broken image.
This file is img.php
The broken image is img.php
How can I fix this?
imagepng($image, "test.png");if you’re saving the image to a file, why are you expecting it to be output to the browser? If you want it to be output directly, just useimagepng($image);Also, the header call needs to be before anything is output.