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..."""