如何在 ImageMagick 中嵌入远程图像
我正在尝试使用 ImageMagick 的 iMagick 包装器从不在我的服务器上的图像生成简单的缩略图。由于某种原因,以下代码在调用时不会显示任何内容:
<?php
$image = new Imagick("http://kunaki.com/ProductImage.ASP?T=I&ST=FO&PID=PX003Y9EDJ");
$image->thumbnailImage(100, 0);
header( "Content-Type: image/jpg" );
echo $image;
?>
我也尝试过使用 http://kunaki.com/ProductImage.ASP?T=I&ST=FO&PID=PX003Y9EDJ.jpg无济于事。
根据下面的评论,我也尝试过这一点,但没有结果,但不确定语法是否正确。
<?php
$kunaki_image = file_get_contents("http://kunaki.com/ProductImage.ASP?T=I&ST=FO&PID=PX003Y9EDJ");
$name = tempnam("/tmp", "kunaki");
$final = file_put_contents($name, $kunaki_image);
$image = new Imagick($final);
$image->thumbnailImage(100, 0);
header( "Content-Type: image/jpg" );
echo $image;
?>
有人有什么建议吗?
谢谢!
I'm trying to do a simple thumbnail generation from an image that isn't located on my server using the iMagick wrapper for ImageMagick. For some reason, the following code will not display anything when called:
<?php
$image = new Imagick("http://kunaki.com/ProductImage.ASP?T=I&ST=FO&PID=PX003Y9EDJ");
$image->thumbnailImage(100, 0);
header( "Content-Type: image/jpg" );
echo $image;
?>
I've also tried using http://kunaki.com/ProductImage.ASP?T=I&ST=FO&PID=PX003Y9EDJ.jpg
to no avail.
Based on comments below, I've attempted this as well with no results, but am not sure if the syntax is correct.
<?php
$kunaki_image = file_get_contents("http://kunaki.com/ProductImage.ASP?T=I&ST=FO&PID=PX003Y9EDJ");
$name = tempnam("/tmp", "kunaki");
$final = file_put_contents($name, $kunaki_image);
$image = new Imagick($final);
$image->thumbnailImage(100, 0);
header( "Content-Type: image/jpg" );
echo $image;
?>
Does anyone have any suggestions?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我必须对 Youtube 做同样的事情...您需要将文件路径传递给 ImageMagic,而不是 file_put_contents 实例。
I had to do the same thing with Youtube... you need to pass the file path to ImageMagic, not the file_put_contents instance.
ImageMagick 的构造函数记录不完整所以我不能确定,但也许 Imagick 无法处理远程文件路径。
尝试单独获取它,例如使用
file_get_contents()
或curl
。将其以临时名称存储在本地,然后将其传递。ImageMagick's constructor is badly documented so I can't tell for sure, but maybe Imagick can't deal with remote file paths.
Try fetching it separately e.g. using
file_get_contents()
orcurl
. Store it locally under a temporary name, and pass it that.如果您喜欢 cUrl,
if you perfer cUrl,
进行一点改进以避免在磁盘上写入:
a little improvement to avoid writing on the disk: