1

in my php code, I get an image in a variable. e.g.:

$src_image=  imagecreatefromjpeg(my_jpeg_path);

I want to output it as an image. So i tried this:

$src_image=  imagecreatefromjpeg(my_jpeg_path);
header('Content-type: image/jpeg');
imgaejpeg($src_image);

But this leads me to an error. the header(..) is assumed a global header and the browser replies:

The image “http://localhost:8081/backend_dev.php/poster/makenew” cannot be displayed because it contains errors.

How do I fix it?

P.S.: I know I can save the image by fwrite and the use image tags but I'll prefer to know whether my method can be made to work.

UPDATE: at this time, I didn't need to see the image itself. I only needed to use the image in another page. in that case doing <img src = '...' /> worked fine. But later I investigated a little and I ended up learning

Symfony output image """Cannot modify header information - headers already sent by..."""

Community
  • 1
  • 1
prongs
  • 9,422
  • 21
  • 67
  • 105

1 Answers1

2

This:

imgaejpeg($src_image);

Is spelt wrong, unless that is just a typo here, that will be your problem. If it is just a typo here, then comment out the header line and the imagejpeg line and see if there are any errors being written, as that will cause an error in the jpeg rendering.

Jim
  • 18,673
  • 5
  • 49
  • 65
  • I was gonna discard this as a stupid answer but turns out it wasn't. Thanks. But still It doesn't show as an image. It shows some weird characters in some weird encoding. You know, the way an image file looks in a text editor. Some way around that? – prongs Dec 09 '11 at 19:11
  • @prongs It seems like you may have the header line commented out still, make sure it is still there and being executed. Without the header line, it is just plain text and spits out the binary data. – Jim Dec 09 '11 at 20:16