1

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
)
AbdelHady
  • 9,334
  • 8
  • 56
  • 83
  • And your question is? – hakre Jul 07 '13 at 15:28
  • Which Imagine version are you using? Which GD version are you using? Which PHP version are you using? – hakre Jul 07 '13 at 15:40
  • latest. You think could it be that the uploading code (using curl) changes something in the image? – AbdelHady Jul 07 '13 at 15:59
  • When asking for more details - and so that it makes sense for other users naturally (*always* have those in mind) - please provide concrete version numbers for the softwares I asked for. Just saying you're using *"latest"* is of *no use* at all. – hakre Jul 07 '13 at 16:01
  • Are you sure the exception is triggered by using the `open()` method? – hakre Jul 07 '13 at 16:05
  • yes it is in `open()` method – AbdelHady Jul 07 '13 at 16:09
  • Hmm, Please tell the filename and line of code where the exception is thrown. Also please add the backtrace. Because as far as I can see, inside the `open()` method that exception is not thrown. So I'm puzzled how the code inside the `load()` method is triggered via `open()`. – hakre Jul 07 '13 at 16:13
  • Open() calls read() which calls load() ! – AbdelHady Jul 07 '13 at 17:02
  • if that's how it gets invoked, see my answer. it's a format that is not supported.The problem I can see with the resource you're trying to open is that the HTTP response headers mismatch the file-type. – hakre Jul 07 '13 at 18:35
  • can you also add the output of `print_r(getimagesize($path));` to your question? – hakre Jul 07 '13 at 18:39
  • similar to this question here, i would try ImageMagick / GMagick http://stackoverflow.com/questions/2100875/unable-to-create-gd-image-resource-from-bmp-with-mime-type-image-x-ms-bmp-in-p – waleed.meligy Jul 08 '13 at 17:19

2 Answers2

2

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

Community
  • 1
  • 1
  • you are right, instantiating the Imagine instance like this `$_imagine = new \Imagine\Gmagick\Imagine();` solved the problem – AbdelHady Jul 09 '13 at 11:03
0

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • I've tried the latest but with the same result with this image – AbdelHady Jul 07 '13 at 15:58
  • What you consider to be *"the latest"* might be different to what I named *"the current Imagine version"*. I meant *master* as of 20 minutes ago on Github - see as well the link I've left. Also in a week, users visiting this question will have problems as well to determine the exact Imagine, GD and PHP version for what you just called "latest". Nobody will be able to decipher that information. – hakre Jul 07 '13 at 16:02
  • ok, it was 'master' branch 15 min ago for Imagine, and I'm using PHP 5.4 – AbdelHady Jul 07 '13 at 16:07
  • Please also get GD version: http://php.net/gd_info - An please say which PHP version exactly (some functions used by Imagine not only depend on GD but also on PHP so the exact version is *very* useful). Your exact version numbers are required to know because that file is served with a mismatch between the HTTP response mime-type, the common used file-extension in the URI and the magic numbers in the raw binary data: http://goo.gl/V74tc – hakre Jul 07 '13 at 16:15