How to install ImageMagick php extension for use on IIS server on windows server

丶灬走出姿态 提交于 2021-01-15 10:54:23

问题


I have a windows web server 2012r2 and wish to install Imagemagick php extension on it, but everything I've tried following has failed to get it to show up in phpinfo().

How can I get imagemagick running? I cannot find working installation steps for IIS.


回答1:


Eventually I ended up on a blogpost, which is a repost of a deleted post by PhilipD which was posted in a wrong format and not corrected. So the question was deleted.

I'm reposting the answer of PhilipD here so it can be found more easily for people encountering the same problem, because it took me half a day of frustration to find the blog post that worked. These steps detail a 32 bit installation. I did a 64 bit installation, for my 64bit php.


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.

1. Download the ImageMagick installer

  • Go to http://www.imagemagick.org/

  • Click "Download" from the menu bar

  • Then "Windows Binary Releases" in the top links or scroll down
  • Select the "Win32 dynamic at 16 bits-per-pixel component", make sure you select a dynamic component and not a static.

2. Download the php module for ImageMagick

  • Go to http://windows.php.net/downloads/pecl/releases/imagick/
  • Select the highest version that's not an "RC" (Release Candidate) version – currently 3.4.3
  • Select the entry for the version of PHP (7.1), for VC14, x86, and "NTS" (Non Thread Safe) for IIS
  • Download and save the ZIP file.

3. Download the dependencies package for PHP to load/use ImageMagick

  • Go to http://windows.php.net/downloads/pecl/deps/
  • Select the "ImageMagick" package with the highest version number
    • *note that this might not be the same version as the item in (1.) above
  • Select the "vc14" and "x86" version*

4. Unblock each of the downloaded files

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
    • click OK.

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. Installing the Imagick Application

  • Run ImageMagick-7.0.7-8-Q16-x86-dll.exe to install it
  • Accept the license agreement
  • 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. Install the dependencies

  • Unzip the file you downloaded in step 3.
  • Go into the bin directory
  • 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
  • Go back into the bin directory
  • copy the CORE_RL_*.dll files (20 files) into the folder for the installed version of ImageMagick, such as C:\Program Files (x86)\ImageMagick-7.0.7-Q16 * * On the prompt if you wish to overwrite/rename, select overwrite
    • Note, this will break the command version of Imagick. magick: Wrong JPEG library version: library is 80, caller expects 62

7. Installing the Imagick php extension dll

  • Unzip the file downloaded in step 2.
  • copy the file php_imagick.dll to the "ext" folder for the installed version of PHP on the server, such as C:\php\7.1\ext.

Do not copy the CORE_RL_* files
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 were copied in the step 6.

8. Modify PHP.ini

  • Edit the php.ini file in the PHP software folder, such as “C:\PHP\7.1\php.ini”
  • Add the following line to the section containing the other extensions:

       extension=php_imagick.dll
    

9. Reboot the server.

Restarting IIS does not seem to be sufficient, you need to reboot the entire machine. This probaly has to do with that IIS doesn't recognize the PATH entry Imagick has entered.

10. Test PHPINFO

  • Create a PHP file in the web root, containing the following:

  • Access this file in a web browser,

  • Search for the “Imagick” section that should now exist in the PHPINFO output.

It should look like the following:

imagick imagick module: enabled imagick module version 3.4.3
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version ImageMagick 6.9.3-7 Q16 x86 2016-03-27 http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 6.9.3-7 Q16 x86 2016-03-27 http://www.imagemagick.org
ImageMagick copyright Copyright (C) 1999-2015 ImageMagick Studio LLC
ImageMagick release date 2016-03-27
ImageMagick number of supported formats: 216
ImageMagick supported formats 3FR, AAI, AI, ART, ARW, AVI, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CLIPBOARD, CMYK, CMYKA, CR2, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPS, DPX, DXT1, DXT5, EMF, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FITS, FPX, FRACTAL, FTS, G3, GIF, GIF87, GRADIENT, GRAY, GROUP4, GV, H, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNX, JP2, JPC, JPM, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PICON, PICT, PIX, PLASMA, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCREENSHOT, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBP, WMF, WMV, WPG, X3F, XBM, XC, XCF, XPM, XPS, XV, YCbCr, YCbCrA, YUV

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 ):

<?php
error_reporting(E_ALL); 
ini_set( 'display_errors','1');
/* 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 */
$draw->popPattern();
/* Use the pattern called "gradient" as the fill */
$draw->setFillPatternURL('#gradient');
/* Set font size to 52 */
$draw->setFontSize(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 */
$canvas->drawImage($draw);
/* 1px black border around the image */
$canvas->borderImage('black', 1, 1);
/* Set the format to PNG */
$canvas->setImageFormat('png');
/* Output the image */
header("Content-Type: image/png");
echo $canvas;
?>

Run this PHP file in a browser. It should display an image containing the text "Hello World!".

12. Check for errors

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.

PDF Files require Ghostscript
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.




回答2:


Update to the accepted answer. Environment was Win 7 32bit, IIS 7.5, PHP 7.2(thread safe) by FastCGIModule. Wordpress 5.5.3 agitated for the imagick module. Note: If imagick is required by your code, as of late 2020, the latest non-rc pecl package was php_imagick-3.4.4-7.4, whose php_imagick.dll did not work with php 8.0.

It was discovered that the 'dependencies' package for PHP was not needed. That meant imagemagick was not broken by php dependencies, so it remained viable for windows users and PHP alike.

1. get ImageMagick for windows

Download the dynamic variety of windows ImageMagick-...-x##-dll.exe from https://imagemagick.org/script/download.php#windows. The x## depends on your system. Just for reference, ImageMagick-7.0.10-43-Q16-x86-dll.exe was tested here.

2. get the php_imagick module

Download the latest imagick pecl package that matches the 'Thread Safety' of your php install from https://windows.php.net/downloads/pecl/releases/imagick/. Find 'Thread Safety' in your phpinfo output. Avoid the release candidate packages, those with 'rc#' in their name. For reference, php_imagick-3.4.4-7.2-ts-vc15-x86.zip the thread safe version was tested here. The apparent consensus was to use the non thread safe php offerings on IIS, but either seemed to work. IIS internally disables php's thread management and uses its own. The only file used from this 40mb archive is the 220kb php_imagick.dll. Skip 3.

4. Unblock the downloads

Opend their properties, and click the 'Unblock' button if it appears.

5. Install Imagemagick for windows

Run the exe and don't accept all the defaults at your peril. The installation wizard will update the PATH environment variable, allowing php commands to reach the imagick installation, after a system reboot. I hear those snickers.

6. PHP Dependencies Not Needed

Regarding the vanilla Imagemagick installation, the CORE_RL_.dll were in the root, while the IM_MOD_RL_.dll files, referred to in other installation directions as php dependencies, were located in the root/modules/coders/ directory. Why not try php on the vanilla install before overwriting 150+ dlls and breaking the original install? What changed, or when is unknown, but both php_magick.dll and magick.exe seemed happy to share the original install. In other words, imagick on the command line still worked. Until further notice, the 'dependencies' are not considered as such.

7. & 8. Install the php_imagick module

Extract php_imagick.dll from the zip archive to the php extensions directory. Add the line "" to a php.ini parsed by PHP.

9. & 10. Confirm imagick module load by PHP

Reboot if you haven't since installing Imagemagick for windows. Optionally, look for entries for 'imagick' in the phpinfo() output.

11. Show Me an Image

Quick test from the cmdline

magick wizard: %temp%/wizard.jpg
magick %temp%/wizard.jpg win:

A php imagick example
I lied; use a second file from the module zip. Extract examples/polygon.php to your site, then browse to polygon.php to confirm some functionality of imagick module.

I include a condensed version here for those just looking for a simple test.

<?php
// polygon.php
$Imagick = new Imagick();
$ImagickDraw = new ImagickDraw();
$ImagickPixel = new ImagickPixel();
$array = array( array( "x" => 378.1, "y" => 81.72 ),
                array( "x" => 381.1, "y" => 79.56 ),
                array( "x" => 384.3, "y" => 78.12 ),
                array( "x" => 387.6, "y" => 77.33 ),
                array( "x" => 391.1, "y" => 77.11 ),
                array( "x" => 394.6, "y" => 77.62 ),
                array( "x" => 397.8, "y" => 78.77 ),
                array( "x" => 400.9, "y" => 80.57 ),
                array( "x" => 403.6, "y" => 83.02 ),
                array( "x" => 523.9, "y" => 216.8 ),
                array( "x" => 526.2, "y" => 219.7 ),
                array( "x" => 527.6, "y" => 223 ),
                array( "x" => 528.4, "y" => 226.4 ),
                array( "x" => 528.6, "y" => 229.8 ),
                array( "x" => 528.0, "y" => 233.3 ),
                array( "x" => 526.9, "y" => 236.5 ),
                array( "x" => 525.1, "y" => 239.5 ),
                array( "x" => 522.6, "y" => 242.2 ),
                array( "x" => 495.9, "y" => 266.3 ),
                array( "x" => 493, "y" => 268.5 ),
                array( "x" => 489.7, "y" => 269.9 ),
                array( "x" => 486.4, "y" => 270.8 ),
                array( "x" => 482.9, "y" => 270.9 ),
                array( "x" => 479.5, "y" => 270.4 ),
                array( "x" => 476.2, "y" => 269.3 ),
                array( "x" => 473.2, "y" => 267.5 ),
                array( "x" => 470.4, "y" => 265 ),
                array( "x" => 350, "y" => 131.2 ),
                array( "x" => 347.8, "y" => 128.3 ),
                array( "x" => 346.4, "y" => 125.1 ),
                array( "x" => 345.6, "y" => 121.7 ),
                array( "x" => 345.4, "y" => 118.2 ),
                array( "x" => 346, "y" => 114.8 ),
                array( "x" => 347.1, "y" => 111.5 ),
                array( "x" => 348.9, "y" => 108.5 ),
                array( "x" => 351.4, "y" => 105.8 ),
                array( "x" => 378.1, "y" => 81.72 ),
              );
$ImagickPixel->setColor( 'gray' );
$Imagick->newImage( 700, 500, $ImagickPixel );
$Imagick->setImageFormat( 'png' );
$ImagickDraw->polygon( $array );
$Imagick->drawImage( $ImagickDraw );
header( "Content-Type: image/{$Imagick->getImageFormat()}" );
echo $Imagick->getImageBlob( );
?>


来源:https://stackoverflow.com/questions/55967226/how-to-install-imagemagick-php-extension-for-use-on-iis-server-on-windows-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!