How do I process jpg files using ImageMagick (IMagick API)? I am getting an exception, NoDecodeDelegateForThisImageFormat, whenver I try

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

  •  21-09-2019
  •  | 
  •  

문제

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 a NoDecodeDelegateForThisImageFormat exception.

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top