如何使用php渲染远程图像? [英] How can I render a remote image with php?
本文介绍了如何使用php渲染远程图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是jpg:http://i.stack.imgur.com/PIFN0.jpg
假设我要从/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);
?>
我希望/sample.php
显示图像.但这是行不通的.我得到的只是一张破碎的图像.我在做什么错了?
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?
推荐答案
使用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渲染远程图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文