doubian0284 2015-06-17 01:43
浏览 52
已采纳

Imagick将外部图像解释为HTML

The problem I'm having is that when saving an image from a specific external website (not all websites), I get an error where the image is interpreted as html and not as another image format.

So far, this website is the only site that I've experienced this problem on, but I definitely need to find a solution.

Link to the images: http://www.nycvelo.com/bike-of-the-week-nicks-geekhouse-commuter/

An image to test with: http://www.nycvelo.com/wp-content/uploads/2013/10/Nicks-Geekhouse-7.jpg

Code from line 86:

$imageURL = 'http://www.nycvelo.com/wp-content/uploads/2013/10/Nicks-Geekhouse-7.jpg';

// Get image file from imagick
$ImagickImage = new Imagick($imageURL);

Error:

Fatal error:  Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `HTML' @ error/constitute.c/ReadImage/535' in uploader.php:86
Stack trace:
#0 uploader.php(86): Imagick->__construct('http://www.nycvelo.com/wp-content/uploads/2013/10/Nicks-Geekhouse-7.jpg')

As far as I can tell, there is no "html" delegate in the first place, nor would it make sense to have one, so perhaps this requires a solution outside of ImageMagick/Imagick?

Update

I ran a test on the file to see what headers were sent back and this is what I got after using file_get_contents.

array(9) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(23) "Content-Type: text/html"
  [2]=>
  string(17) "Connection: close"
  [3]=>
  string(23) "Cache-Control: no-cache"
  [4]=>
  string(17) "Connection: close"
  [5]=>
  string(20) "Content-Length: 6195"
  [6]=>
  string(81) "X-Iinfo: 5-12048231-0 0CNN RT(1434509018550 6) q(1 -1 -1 -1) r(1 -1) B10(4,289,0)"
  [7]=>
  string(163) "Set-Cookie: visid_incap_264353=osbiSagORl2MGqb2cebUn9regFUAAAAAQUIPAAAAAAAUiLr5I31XtpMPuiNCWNQH; expires=Thu, 15 Jun 2017 13:43:05 GMT; path=/; Domain=.nycvelo.com"
  [8]=>
  string(118) "Set-Cookie: incap_ses_239_264353=XJXubnJwpRuBGVGGahpRA9regFUAAAAAbY2asXWHPVkKb5NEpRJyXg==; path=/; Domain=.nycvelo.com"
}
  • 写回答

2条回答 默认 最新

  • duanliexi1052 2015-06-17 11:44
    关注

    I strongly recommend not using Imagick for downloading images from other servers. Either use CURL or some other library that gives you adequate control over the download (including being able to see redirects, incorrect content types, etc), and then process the image with Imagick once it is downloaded correctly.

    Source - I'm the maintainer for Imagick.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?