Image cannot be displayed because it contains errors [Image generator]

The presence of some problems with the image generator. Maybe you find out what the problem is? I get: "The image cannot be displayed because it contains errors", I upload the image file, but there are no errors.

<?php if(isset($_GET['id']) && $_GET['id']){ // require('../libs/global.inc.php'); $id = $_GET['id']; $imagePath = "gov_220.jpg";//$track->getImg($id); $framePath = "otgFrame.png"; $fontsize = 14; $font = 'times.ttf'; $artistName = "bla bla";//$view->CutTheName("by ".$track->getArtist($id), 16); //$artistName = iconv(mb_detect_encoding($artistName, mb_detect_order(), true), "UTF-8", $artistName); $trackName = "la la";//$view->CutTheName($track->getName($id),16); $photo = imagecreatefromjpeg($imagePath); $w = imagesx($photo); $h = imagesy($photo); $new_image = imagecreatetruecolor(200, 200); imagecopyresampled($new_image, $photo, 0, 0, 0, 0, 200, 200, $w, $h); imagealphablending($new_image,true); $frame = imagecreatefrompng($framePath); imagecopy($new_image,$frame,0,0,0,0,200,200); $fontcolor = imagecolorallocate($new_image, 255, 255, 255); imagettftext($new_image, $fontsize, 0,2,177,$fontcolor, $font, $trackName ); $fontcolor = imagecolorallocate($new_image, 246, 228, 6); imagettftext($new_image, $fontsize, 0,2,196,$fontcolor, $font, $artistName ); header('Content-type: image/png'); imagepng($new_image); imagedestroy ($new_image); } ?> 
+4
source share
2 answers

Open the image in a text editor, I think you will find a warning from php.

+5
source

Removing header('Content-type: image/png'); and adding the file name to imagepng($new_image,"Test.png",9); may have solved your problem ..

and use this image with the HTML img tag. those. <img src="Test.png" alt="">

+3
source

Source: https://habr.com/ru/post/1496770/


All Articles