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

StackOverflow https://stackoverflow.com/questions/17513472

  •  02-06-2022
  •  | 
  •  

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
)
有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top