简体   繁体   中英

Image gets messed up while trying to add text PHP

I'm trying to add text to a predefined image, but have failed to do so. The code I am using is the following:

<?php   
header("Content-type: image/png");
if(file_exists("stats_gen.png")){ unlink("stats_gen.png");} //delete old version
$string = "text";
$im     = imagecreatefrompng("stats.png");
$textcolor = imagecolorallocate($im, 0, 0, 255);
imagestring($im, 5, 0, 0, $string, $textcolor);
imagepng($im); //show the image for debug purposes
imagepng($im, "stats_gen.png"); //save the image
imagedestroy($im);
?>

stats.png looks like this: Oh, image format not supported. Well, this: http://lolmewn.nl/stats/stats.png and ends up like http://lolmewn.nl/stats/stats_gen.png which looks crap. What am I doing wrong? Google doesn't seem to give any answers...

Make the image background un-transparent. Heh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM