Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

image

gd

Having some problems with image generator. Maybe you will find out what's the problem? I'm getting: "The image cannot be displayed because it contains errors", I'm downloading image file, but there is 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);
}
?>
like image 965
Aleksandr Golubovskij Avatar asked Jan 12 '23 15:01

Aleksandr Golubovskij


2 Answers

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

like image 112
Marek Avatar answered Jan 26 '23 01:01

Marek


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

and use that image with img tag of HTML. i.e. <img src="Test.png" alt="">

like image 25
Shaunak Shukla Avatar answered Jan 26 '23 00:01

Shaunak Shukla