这是一个 jpg:http://i.stack.imgur.com/PIFN0.jpg
假设我想从 /img.php?file_name=PIFN0.jpg
以下是我尝试完成这项工作的方法:
/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);
?>
我希望 /sample.php
显示图像。但这不起作用。我得到的只是一张破损的图像。我做错了什么?
最佳答案
使用imagecreatefromjpeg
:
<?php
$url = 'http://i.stack.imgur.com/' . $_GET['file_name'];
header('Content-type: image/jpeg');
imagejpeg(imagecreatefromjpeg($url));
?>
引用:http://php.net/manual/en/function.imagecreatefromjpeg.php
关于php - 如何使用 php 渲染远程图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12629410/