Imagick-无法从URL读取图像文件. [英] Imagick - Can't read image files from URL.
问题描述
我正在使用此代码段在不同的网站上阅读图片:
I'm using this snippet for reading images on different websites:
$image = new Imagick('http://lp.hm.com/hmprod?set=key[source],value[/model/2012/P01 05156 06204 80 1175 4.jpg]&set=key[rotate],value[]&set=key[width],value[]&set=key[height],value[]&set=key[x],value[]&set=key[y],value[]&set=key[type],value[STILL_LIFE_FRONT]&call=url[file:/product/large]');
但是有时候,我会收到这样的错误(大约20%的时间):
But sometimes, I get an error like this (about 20% of the time):
ImagickException
Unable to read the file: http://lp.hm.com/hmprod?set=key[source],value[/model/2012/P01 05156 06204 80 1175 4.jpg]&set=key[rotate],value[]&set=key[width],value[]&set=key[height],value[]&set=key[x],value[]&set=key[y],value[]&set=key[type],value[STILL_LIFE_FRONT]&call=url[file:/product/large]
Imagick->__construct()
该错误在整个域中似乎是一致的,但是有时同一域中的图像与图像之间是不同的.
The error seems to be consistent through this whole domain, but sometimes it's different from image to image on the same domain.
为什么这是个问题?
我们该如何解决?
有替代解决方案吗?
Why is this a problem?
How can we fix it?
Is there an alternative solution?
推荐答案
步骤1:获取URL
$url = 'http://blablabla.com/blabla.jpeg';
第2步:将博客内容保存到变量
STEP 2 : Save blog content to a variable
$image = file_get_contents($url);
第3步:创建Imagick对象
STEP 3 : Create Imagick object
$img = new Imagick();
第4步:指示imagick对象读取图像的斑点内容
STEP 4 : Instruct imagick object to read blob content of the image
$img -> readImageBlob($image);
第5步:在图像上保存(或执行操作)
STEP 5 : Save (or do operations) on image
$img -> writeImage('/var/www/html/uploads/img.jpg');
第6步:销毁imagick实例
STEP 6 : Destroy imagick instance
$img -> destroy();
这篇关于Imagick-无法从URL读取图像文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!