windows下php imagick 报错 no decode delegate for this image format `JPEG' 的解决方法
windows下使用 php imagick 时报错:no decode delegate for this image format `JPEG' @ error/constitute.c/ReadImage/501
或者 no decode delegate for this image format `PNG'
或者 no decode delegate for this image format `BMP'
原因:IM_MOD_ 安装不完整
解决方法:根据 https://mlocati.github.io/articles/php-windows-imagick.html 提示,完整安装 imagick
下载对应的版本:
Version | Thread Safe | Architecture | Estension | ImageMagick |
---|---|---|---|---|
7.0 | Yes | x86 | php_imagick-3.4.3-7.0-ts-vc14-x86.zip | ImageMagick-6.9.3-7-vc14-x86.zip |
7.0 | Yes | x64 | php_imagick-3.4.3-7.0-ts-vc14-x64.zip | ImageMagick-6.9.3-7-vc14-x64.zip |
7.0 | No | x86 | php_imagick-3.4.3-7.0-nts-vc14-x86.zip | ImageMagick-6.9.3-7-vc14-x86.zip |
7.0 | No | x64 | php_imagick-3.4.3-7.0-nts-vc14-x64.zip | ImageMagick-6.9.3-7-vc14-x64.zip |
Once you downloaded the correct files:
解压
php_imagick-….zip
php_imagick.dll
放到php的ext
目录解压
ImageMagick-….zip
把以下字母开头的DLL文件放到PHP的根目录,即php.exe
所在目录, or to a directory present in your PATH environment variable,:CORE_RL_
IM_MOD_RL_
在
php.ini
中添加:extension=php_imagick.dll
重启 Apache/NGINX Windows 等web服务
现在测试一下,看看是否正常运行:
<?php
$image = new Imagick();
$image->newImage(1, 1, new ImagickPixel('#ffffff'));
$image->setImageFormat('png');
$pngData = $image->getImagesBlob();
echo strpos($pngData, "\x89PNG\r\n\x1a\n") === 0 ? 'Ok' : 'Failed';
以上是以php7为例,其它版本请参照以下方法查找:
查看你的PHP版本:
php -i|find "PHP Version"
查看你的PHP thread 模式
php -i|find "Thread Safety"
You’ll haveenabled
for thread safe ordisabled
for not thread safe32还是64位版本
php -i|find "Architecture"
You’ll havex86
for 32 bits andx64
for 64 bits
根据上面查到的信息,下载适合的版本