Installing ImageMagick for use with PHP and IIS on a Windows Server 2012R2 and Windows 10
Submitted by Anthony Bouch on 23 April, 2018
Full disclosure: This is not my guide. This is a repost of a Stackoverlflow post - https://stackoverflow.com/questions/46960358/installing-imagemagick-the… by user PhilipD. After hours of searching, this was the most complete and helpful guide we could find and it saved us hours of frustration. The post on Stackoverflow has been 'put on hold' because it's not really a question and so I'm reposting here.
Philip's instructions worked flawlessly, including replacing all of the 32bit x86 libs and dependencies with 64 bit versions on a Windows 10 Pro installation, also with IIS and PHP (PHP located in C:\php, and ImageMagick installed to C:\ImageMagick).
Here's the original post...
We have a Windows Server 2012R2 machine with IIS enabled, and PHP (v7.1.10) installed and enabled in IIS.
We needed to add ImageMagick to this system, to allow for image file conversions from PHP code in web pages in a virtual directory (application) on the server.
I read through several questions and answers about this on StackOverflow, many of which are a few years old or refer to older versions of ImageMagick and/or PHP. Based largely on various information from some of these articles, and a bit of trial-and-error, we now have a working installation of ImageMagick on this server that can be used from PHP web pages in IIS on the server.
If anyone is interested, the following are the steps I took to get this all working. Please feel free to add suggestions or correct anything that seems to be incorrect.
This is on a Windows Server 2012R2 (64-bit) server, using IIS as the web server application. However, I installed the 32-bit version of all the ImageMagick-related software because the web server application (IIS) is 32-bit. The following shows versions that were current/latest as of October-2017.
Note that this may or may not be necessary depending on how you downloaded it, but you should always check and "unblock" downloaded files if needed. Right-click on each file and select “Properties” from the popup menu; if the properties dialog shows the text “This file came from another computer and might be blocked to help protect this computer”, click the “Unblock” button, and then click OK. Note that if you don’t “unblock” the downloaded files, especially for ZIP files, the individual files that are installed or copied can still be marked as “blocked” and this can sometimes cause some strange issues when running the software.
(5) Run ImageMagick-7.0.7-8-Q16-x86-dll.exe to install it; accept the license agreement, and accept the defaults on each screen in the install process.
After the installation completes, to test that it was successful, open a command prompt and run the following two commands:
magick wizard: wizard.jpg
magick wizard.jpg win:
This should display an "IMDisplay" window showing a sketch/image of a wizard at an easel creating a Mona Lisa portrait.
(6) Unzip the ImageMagick-6.9.3-7-vc14-x86 ZIP file.
From the "bin" folder in this package, copy the IM_MOD_RL_*.dll files (125 files) into the folder for the installed version of ImageMagick, such as C:\Program Files (x86)\ImageMagick-7.0.7-Q16.
From the "bin" folder in this package, copy the CORE_RL_*.dll files (20 files) from here to the folder for the installed version of ImageMagick, such as C:\Program Files (x86)\ImageMagick-7.0.7-Q16, replacing the existing files in that folder.
(7) Unzip the php_imagick-3.4.3-7.1-nts-vc14-x86 ZIP file.
From this ZIP's contents, copy the file php_imagick.dll to the "ext" folder for the installed version of PHP on the server, such as “C:\Program Files (x86)\PHP\v7.1\ext”.
Note: In some articles on the web, you will see instructions to also copy the CORE_RL_* files from this kit to replace the files in the ImageMagick folder, but this is incorrect; the appropriate versions of these files are copied in the previous step.
(8) Edit the php.ini file in the PHP software folder, such as “C:\Program Files (x86)\PHP\v7.1”
Add the following line to the section containing the other extensions:
(9) Reboot the server. Note that restarting IIS does not seem to be sufficient, you need to reboot the machine.
(10) Test PHPINFO
Create a PHP file in the web root, containing the following:
// Show all information, defaults to INFO_ALL
Run this file in a web browser, and search for the “imagick” section that should now exist in the PHPINFO output. It should look like the following:
Important: If the “supported formats” section does not show any formats, or only shows a small number of formats, then the most likely cause is that you missed copying one or more of the IM_MOD_RL_* or CORE_RL_* DLL files into the ImageMagick folder, or you copied them from the “php_magick” kit instead.
(11) Test image generation using ImageMagick in PHP
Create a PHP file in the web root, containing the following (I copied this from one of the entries in this item Verify ImageMagick installation ):
/* Create a new imagick object */
$im = new Imagick();
/* Create new image. This will be used as fill pattern */
$im->newPseudoImage(50, 50, "gradient:red-black");
/* Create imagickdraw object */
$draw = new ImagickDraw();
/* Start a new pattern called "gradient" */
$draw->pushPattern('gradient', 0, 0, 50, 50);
/* Composite the gradient on the pattern */
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);
/* Close the pattern */
/* Use the pattern called "gradient" as the fill */
/* Set font size to 52 */
/* Annotate some text */
$draw->annotation(20, 50, "Hello World!");
/* Create a new canvas object and a white image */
$canvas = new Imagick();
$canvas->newImage(350, 70, "white");
/* Draw the ImagickDraw on to the canvas */
/* 1px black border around the image */
$canvas->borderImage('black', 1, 1);
/* Set the format to PNG */
/* Output the image */
Run this PHP file in a browser. It should display an image containing the text "Hello World!".
(12) Check the php-errors.log file for any errors.
You can find the defined location of the php-errors.log file in the php.ini file. Check this file for any recent errors related to the ImageMagick installation.
Note: After installing and setting up all of the above, ImageMagick could be used in PHP to convert images, but it could not be used to convert PDF files to images. For this final step, it seemed to be necessary to also install Ghostscript - from https://www.ghostscript.com/download/gsdnld.html and it only worked correctly if I installed the 64-bit version of Ghostscript (even though everything else that I installed was the 32-bit version). Installing Ghostscript was all that was needed; no changes to php.ini or any other configuration was required.