Unable to display image through PHP in <img> tag

98 Views Asked by At

I'm trying to display images using the output of a PHP file in a <img> tag as I want to process the image with Imagick before displaying it. The following code works fine when I call it in the browser address bar:

img.php

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

$file = $_GET['image'];

$image = @file_get_contents($file);
$im = new Imagick();
$im->readImageBlob($image);

$im->trimImage(0.1 * \Imagick::getQuantum());
$im->scaleImage(180, 180, true);
echo $im->getImageBlob();

But when I use the above code into HTML the image is simply not shown:

<img src="img.php?image=http://www.emtshop.it/264024-category_default/tv-led-smart-tech-315-wide-smt32f30hc4u1b1-smart-tv-android-dvb-t2-s2-hd-1366x768-black-ci-slot-3xhdmi-2xusb-vesa.jpg" />

Removing the echo in the last line does not solve the issue.

UPDATE

Browser's developer tools reports Error 404: www.mysite.com/img.php?image=http://... where www.mysite.com is my server where I'm running the script (while the image resides on a different server). But, as asked in my comment below, why it is looking for a file? Shouldn't be the result of a image processing job?

If I call img.php?image=http://... directly in the browser's address bar the image is shown correctly.

0

There are 0 best solutions below