本文共 7984 字,大约阅读时间需要 26 分钟。
转自
http://herbmiller.me/2016/06/16/installing-imagick-php-7/
If you’re running PHP 7 on Windows and you want to use the Imagick PHP extension then you may want to refer to this post for some download and installation instructions.
I recently spent far too long trying to convince incompatible binaries that they should work together. All I wanted to do was to write some code that would automatically correct the orientation of an uploaded image, based on the value of the Orientation field in the image’s EXIF data. And, in order to test it, I needed a method of setting the orientation.
To do that I needed to install the Imagick PHP Extension. I thought that the installation would be doddle. It wasn’t.
I chased a lot of wild geese and followed many red herrings until I eventually found the correct hint for the location of the ImageMagick binary files upon which the Imagick PHP extension is dependent.
I hope that you’ll find these notes to be useful.
php.ini
to enable the php_imagick
extension. Use php -i
to run phpinfo()
and look at the first few lines of the output
PHP Version => 7.0.7System => Windows NT QW 10.0 build 10586 (Windows 10) AMD64Build Date => May 25 2016 12:48:08Compiler => MSVC14 (Visual C++ 2015)Architecture => x64...Loaded Configuration File => C:\php7\php.ini...Thread Safety => enabled...
php_imagick-3.4.3rc1-7.0-ts-vc14-x64.zip
Determine the directory for extensions by checking for the extension_dir
directive in your phpinfo output.
Directive => Local Value => Master Valueextension_dir => C:\php7\ext => C:\php\ext
If the top level directory doesn’t match that from which PHP is run then you should either correct the local value or fully qualify the file name of the extension.
extension=c:/php7/ext/php_imagick.dll
Or do both.
Since PHP extensions are loaded dynamically, you need to tell PHP where to find them. It doesn’t use the PATH
for this. You either need to fully qualify the file name or define the extension_dir
directive.
For php_imagick.dll
to be loadable all the DLLs upon which it is statically dependent also need to be accessible.
When ImageMagick is installed then you will be using its DLLs. In the mean time you need to extract all of them, ensuring that they are in a directory that’s in your PATH.
You have two options. Copy the files into a directory that’s already in your PATH, or add the directory to your PATH.
I chose to install all the .dll files ( php_imagick.dll and 7 starting CORE_ ) into c:\php7\ext
and added that directory to my PATH, after the entry for C:\php7
.
With the extension installed it is now possible to determine the version of ImageMagick upon which php_imagick.dll
is dependent.
Run php -i
and check the output.
imagickimagick module => enabledimagick module version => 3.4.3RC1imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernelImagick compiled with ImageMagick version => ImageMagick 6.9.3-7 Q16 x64 2016-03-27 http://www.imagemagick.orgImagick using ImageMagick library version => ImageMagick 6.9.3-7 Q16 x64 2016-03-27 http://www.imagemagick.orgImageMagick copyright => Copyright (C) 1999-2015 ImageMagick Studio LLCImageMagick release date => 2016-03-27
The version of ImageMagick you will need is shown in “Imagick compiled with ImageMagick version”.
Now you won’t find what you’re looking for at www.imagemagick.org. You need to go to
The file I downloaded was ImageMagick-6.9.3-7-vc14-x64.zip
bin
directory from the ImageMagick zip file to a directory of your choice. I chose C:\ImageMagick-6.9.3-7Use “Edit the system environment variables” to edit the System variables section.
SystemPropertiesAdvanced
.PATH
for ImageMagick ensuring it is before the entry for the PHP extensions.MAGICK_HOME
setting it to the ImageMagick home directory.Rebooting is the simplest way of ensuring that your system notices the changes you have made.
If you’re just running PHP from the Command Prompt you should be able to get away with closing one and opening a new Command Prompt.
Or you may choose to use ApacheMonitor to stop and restart your web server. But this may not pick up system environment changes.
ImageMagick number of supported formats
.
ImageMagick number of supported formats: => 234ImageMagick supported formats => a, long, list, of, formats, comma, space, separated, including, common, ones, such, as, JPG, PDF, PNG
If you get the following when running php -i
Warning: PHP Startup: Unable to load dynamic library 'c:/php7/ext/php_imagick.dll' - The specified module could not be found. in Unknown on line 0
then you will need to make sure the dependent DLLs are correctly installed.
In phpinfo output, if you do not have the correct version of ImageMagick installed and configured then you will probably see
ImageMagick number of supported formats: => 0ImageMagick supported formats =>
If you try running PHP code that uses Imagick and you get CLI has stopped working
, then you have incompatible versions. Check you don’t have another version of Imagick running.
I got this problem when I was running the latest version ( ImageMagick 7.0.2-0 ) from imagemagick.org.
It’s also possible that php -i
produces the correct output but phpinfo on the browser shows 0 supported formats. Possible solutions:
C:\php7\ext
directory resolved this problem.PATH
also resolved it.MAGICK_HOME
is correctly set in the System environment variables.Note: I chose to update my version of PHP to 7.0.7
Component | URL | Version required |
---|---|---|
PHP 7 | VC14 x64 Thread Safe (2016-May-25 23:02:16) | |
Imagick extension | php_imagick-3.4.3rc1-7.0-ts-vc14-x64.zip | |
ImageMagick runtime | ImageMagick-6.9.3-7-vc14-x64.zip |
Directory/File | Contains |
---|---|
C:\php7 | PHP 7.0.7 thread safe X64 |
C:\php7\php.ini | PHP configuration file |
C:\php7\ext | PHP extensions including php_imagick.dll |
C:\ImageMagick-6.9.3.7 | Extracted files from the ImageMagick .zip file’s bin directory |
Variable | Purpose | Contents |
---|---|---|
PATH | System path | includes C:\ImageMagick-6.9.3-7 C:\php7 and C:\php7\ext in that order |
MAGICK_HOME | ImageMagick home | C:\ImageMagick-6.9.3-7 |
转载地址:http://oqpsi.baihongyu.com/