0

I've a problem with some lines of code. I try to generate a picture with php and the gd2 librarie.

<?php

header('Content-type: image/jpeg');

$im = imagecreatefromjpeg('profil.jpg');
imagejpeg($im);

imagedestroy($im);?>

This code doesn't work. There's no image displayed, just a message : "this image can't be displayed because there's error" displayed in white on grey background.

The picture is well loaded and "$im" is a resource created with "imagecreatefromjpeg"...

If i remove all lines except header('Content-type: image/jpeg');, I've got the same problem.

Who can give me the right way ??

Thanks by advance !

Mickael

moDevsome
  • 189
  • 2
  • 16
  • Can you please post a screenshot of the error message in the browser? I don't really get where the error is coming from. (Browser, PHP, GD, Apache, etc.) – Rudolph Gottesheim Jul 30 '14 at 21:26
  • maybe your image is not a real JPEG image, but a PNG or GIF one. Please do var_dump($im); before `imagejpeg($im)` this may help to debug – Valentin Mercier Jul 30 '14 at 21:28
  • I've already do a var_dump of $img before "imagejpeg", It's return "Resource(3)", so "imagecreatefromjpeg" don't return FALSE. – moDevsome Jul 31 '14 at 06:18

3 Answers3

0

Nmae that php file image.php and call it as source of image tag in another php file. Then that will show the image.

 <img src="image.php" height="250px" width="162px">

Click Here To Download Example From Google

Muhammad Ashikuzzaman
  • 3,075
  • 6
  • 29
  • 53
0

Working good after creating a new php file where I pasted my code.

I think that my file was corrupt.

moDevsome
  • 189
  • 2
  • 16
-1

I just tried your code. The only error I get is when profil.jpg is not present in the same directory. is profil.jpg in the same directory as your .php file ?