Here's a jpg: http://i.stack.imgur.com/PIFN0.jpg
Let's say I'd like this rendered from /img.php?file_name=PIFN0.jpg
Here's how I'm trying to make this work:
/sample.php
<p>Here's my image:</p>
<img src="/img.php?file_name=PIFN0.jpg">
/img.php
<?php
$url = 'http://i.stack.imgur.com/' . $_GET['file_name'];
header('Content-type: image/jpeg');
imagejpeg($url);
?>
I would expect /sample.php
to show the image. But this doesn't work. All I get is a broken image. What am I doing wrong?
No need to use the GD functions:
Use
imagecreatefromjpeg
:Reference: http://php.net/manual/en/function.imagecreatefromjpeg.php
but in the new server, only can read the local images, the remote images is error.
Here is an working example: