opening image with Imagine gives 'An image could not be created from the given input'

浪尽此生 提交于 2019-12-11 07:16:23

问题


I'm using Imagine to resize images after uploading them with curl in /tmp:

$_imagine = new \Imagine\Gd\Imagine();
$mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$image = $_imagine->open($path); // i.e $path = '/tmp/photo.jpg'
// then resizing the $image

It is working fine with any previously uploaded images in my /tmp, but when uploading this image http://newsimg.bbc.co.uk/media/images/67373000/jpg/_67373987_09f1654a-e583-4b5f-bfc4-f05850c6d3ce.jpg then trying to open it with Imagine, it gives the following error:

Fatal error: Uncaught exception 'Imagine\Exception\InvalidArgumentException' with message 'An image could not be created from the given input'

Did anybody know what is wrong with this image that makes it throw this exception?


here is the print_r(getimagesize($path)); as asked by @hakre:

Array
(
    [0] => 464
    [1] => 261
    [2] => 6
    [3] => width="464" height="261"
    [bits] => 32
    [mime] => image/x-ms-bmp
)

回答1:


This is similar to this question answered here: Unable to create GD image resource from BMP with MIME type 'image/x-ms-bmp' in PHP

To put shortly, this is a BMP image, and GD can't handle it as it seems from this answer, i would try ImageMagick / GMagick




回答2:


If you take a look into the source-code you can directly find the explanation. That Imagine class uses the underlying GD image library of PHP to open images.

The Imagine\Exception\InvalidArgumentException exception message

An image could not be created from the given input

just means that the imagecreatefromstring() function failed.

However, for the current Imagine version this exception should not be triggered on \Imagine\Gd\Imagine::open(). So you're probably using a different version.



来源:https://stackoverflow.com/questions/17513472/opening-image-with-imagine-gives-an-image-could-not-be-created-from-the-given-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!