在Windows中安装ImageMagick PHP扩展

管理员
管理员 2021-3-22

1、安装与配置
NOTE I recently released a PowerShell module that will let you install the PHP imagick extension simply with Install-PhpExtension imagick

In order to install the imagick PHP extension on Windows, you need to know the exact version of your PHP. To do this: open a command prompt and enter these commands:

  • Determine the PHP version:
    php -i|find "PHP Version"

  • Determine the thread safety
    php -i|find "Thread Safety"
    You’ll have enabled for thread safe or disabled for not thread safe

  • Determine the architecture
    php -i|find "Architecture"
    You’ll have x86 for 32 bits and x64 for 64 bits

Once you determined the above parameters, you have to download the dll of the PHP extension and the ImageMagick archive using the following table:


VersionThread SafeArchitectureEstensionImageMagick
5.5Yesx86php_imagick-3.4.3-5.5-ts-vc11-x86.zipImageMagick-6.9.3-7-vc11-x86.zip
5.5Yesx64php_imagick-3.4.3-5.5-ts-vc11-x64.zipImageMagick-6.9.3-7-vc11-x64.zip
5.5Nox86php_imagick-3.4.3-5.5-nts-vc11-x86.zipImageMagick-6.9.3-7-vc11-x86.zip
5.5Nox64php_imagick-3.4.3-5.5-nts-vc11-x64.zipImageMagick-6.9.3-7-vc11-x64.zip
5.6Yesx86php_imagick-3.4.3-5.6-ts-vc11-x86.zipImageMagick-6.9.3-7-vc11-x86.zip
5.6Yesx64php_imagick-3.4.3-5.6-ts-vc11-x64.zipImageMagick-6.9.3-7-vc11-x64.zip
5.6Nox86php_imagick-3.4.3-5.6-nts-vc11-x86.zipImageMagick-6.9.3-7-vc11-x86.zip
5.6Nox64php_imagick-3.4.3-5.6-nts-vc11-x64.zipImageMagick-6.9.3-7-vc11-x64.zip
7.0Yesx86php_imagick-3.4.3-7.0-ts-vc14-x86.zipImageMagick-6.9.3-7-vc14-x86.zip
7.0Yesx64php_imagick-3.4.3-7.0-ts-vc14-x64.zipImageMagick-6.9.3-7-vc14-x64.zip
7.0Nox86php_imagick-3.4.3-7.0-nts-vc14-x86.zipImageMagick-6.9.3-7-vc14-x86.zip
7.0Nox64php_imagick-3.4.3-7.0-nts-vc14-x64.zipImageMagick-6.9.3-7-vc14-x64.zip
7.1Yesx86php_imagick-3.4.4-7.1-ts-vc14-x86.zipImageMagick-6.9.3-7-vc14-x86.zip
7.1Yesx64php_imagick-3.4.4-7.1-ts-vc14-x64.zipImageMagick-6.9.3-7-vc14-x64.zip
7.1Nox86php_imagick-3.4.4-7.1-nts-vc14-x86.zipImageMagick-6.9.3-7-vc14-x86.zip
7.1Nox64php_imagick-3.4.4-7.1-nts-vc14-x64.zipImageMagick-6.9.3-7-vc14-x64.zip
7.2Yesx86php_imagick-3.4.4-7.2-ts-vc15-x86.zipImageMagick-7.0.7-11-vc15-x86.zip
7.2Yesx64php_imagick-3.4.4-7.2-ts-vc15-x64.zipImageMagick-7.0.7-11-vc15-x64.zip
7.2Nox86php_imagick-3.4.4-7.2-nts-vc15-x86.zipImageMagick-7.0.7-11-vc15-x86.zip
7.2Nox64php_imagick-3.4.4-7.2-nts-vc15-x64.zipImageMagick-7.0.7-11-vc15-x64.zip
7.3Yesx86php_imagick-3.4.4-7.3-ts-vc15-x86.zipImageMagick-7.0.7-11-vc15-x86.zip
7.3Yesx64php_imagick-3.4.4-7.3-ts-vc15-x64.zipImageMagick-7.0.7-11-vc15-x64.zip
7.3Nox86php_imagick-3.4.4-7.3-nts-vc15-x86.zipImageMagick-7.0.7-11-vc15-x86.zip
7.3Nox64php_imagick-3.4.4-7.3-nts-vc15-x64.zipImageMagick-7.0.7-11-vc15-x64.zip
7.4Yesx86php_imagick-3.4.4-7.4-ts-vc15-x86.zipImageMagick-7.0.7-11-vc15-x86.zip
7.4Yesx64php_imagick-3.4.4-7.4-ts-vc15-x64.zipImageMagick-7.0.7-11-vc15-x64.zip
7.4Nox86php_imagick-3.4.4-7.4-nts-vc15-x86.zipImageMagick-7.0.7-11-vc15-x86.zip
7.4Nox64php_imagick-3.4.4-7.4-nts-vc15-x64.zipImageMagick-7.0.7-11-vc15-x64.zip

Once you downloaded the correct files:

  1. Extract from php_imagick-….zip the php_imagick.dll file, and save it to the ext directory of your PHP installation

  2. Extract from ImageMagick-….zip the DLL files located in the bin folder that start with CORE_RL or IM_MOD_RL, and save them to the PHP root directory (where you have php.exe), or to a directory in your PATH variable

  3. Add this line to your php.ini file:
    extension=php_imagick.dll

  4. Restart the Apache/NGINX Windows service (if applicable)

To test if the extension works, you can run this PHP code:

<?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';



2、常见说明

1、Ubuntu子系统使用ImageMagick报错convert-im6.q16: not authorized解决方法

root@Lian:~# convert -density 150 Appendix-A.pdf -quality 90 output.png
convert-im6.q16: not authorized `Appendix-A.pdf' @ error/constitute.c/ReadImage/412.
convert-im6.q16: no images defined `output.png' @ error/convert.c/ConvertImageCommand/3258.

解决修改:

修改配置文件/etc/ImageMagick-6/policy.xml
root@Lian:~/# vim /etc/ImageMagick-6/policy.xml
 
找到这一行:
 
<policy domain="coder" rights="none" pattern="PDF" />
 
修改为:
 
<policy domain="coder" rights="read|write" pattern="PDF" />
 
在下面再增加一行:
 
<policy domain="coder" rights="read|write" pattern="LABEL" />
<policy domain="coder" rights="read|write" pattern="JPG" />
<policy domain="coder" rights="read|write" pattern="PNG" />


注意:修改保存后重启PHP服务即可

回帖
  • 消灭零回复

微信二维码

微信二维码

微信扫码添加微信好友