tags:

views:

244

answers:

1

I am using ImageMagick with the PHP IMagick API to process uploaded jpg files - however, when I try to read a Blob or even read a physical file, I get the exception,

NoDecodeDelegateForThisImageFormat

An example of the code I am using is below -

private function resizeImageBlob($blob, $width, $height) {
    $image = new Imagick();
    $image->readImageBlob($blob);
    $image->resizeImage($width, $height, IMAGICK::FILTER_LANCZOS, 1);
    $resizedBlob = $image->getImageBlob();

    return $resizedBlob;
}

The image that the blob represents is a jpg image, but ImageMagick throws the exception when it tries to read the line

$image->readImageBlob($blob);

Does anybody know why this might be happening?

A: 

I figured out the answer to my problem. The reason the exception was occurring was indeed due to the fact that the library did not have jpeg support built in, but the reason this happened was because the Imagick php extension's version and the ImageMagick library's version were different.

A good way to make sure not to run into this problem is to download both the ImageMagick library and the Imagick php extension, and specifically look at the versions to see that they match.

Alternatively, you can check the version of your Imagick php extension in the php/ext folder by enabling it in your php.ini file, and using

echo phpinfo();

to check the version of the extension. Then, you can download the same version of the ImageMagick library.

Nick