2015-06-17 01:43


  • imagick
  • php
  • imagemagick

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:

An image to test with:

Code from line 86:

$imageURL = '';

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


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('')

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?


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) {
  string(15) "HTTP/1.1 200 OK"
  string(23) "Content-Type: text/html"
  string(17) "Connection: close"
  string(23) "Cache-Control: no-cache"
  string(17) "Connection: close"
  string(20) "Content-Length: 6195"
  string(81) "X-Iinfo: 5-12048231-0 0CNN RT(1434509018550 6) q(1 -1 -1 -1) r(1 -1) B10(4,289,0)"
  string(163) "Set-Cookie: visid_incap_264353=osbiSagORl2MGqb2cebUn9regFUAAAAAQUIPAAAAAAAUiLr5I31XtpMPuiNCWNQH; expires=Thu, 15 Jun 2017 13:43:05 GMT; path=/;"
  string(118) "Set-Cookie: incap_ses_239_264353=XJXubnJwpRuBGVGGahpRA9regFUAAAAAbY2asXWHPVkKb5NEpRJyXg==; path=/;"
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanliexi1052 duanliexi1052 6年前

    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.

    点赞 评论 复制链接分享
  • duanniubeng2265 duanniubeng2265 6年前

    The server may be redirecting your request to some html page somewhere, check the contents of the response to find out if this is the case.

    点赞 评论 复制链接分享