如何安装ImageMagick php扩展以在Windows Server的IIS服务器上使用

问题描述:

我有一个Windows Web服务器2012r2,希望在其上安装Imagemagick php扩展,但是我已经 已尝试以下未能使它显示在phpinfo()中.

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().

如何使imagemagick运行?我找不到IIS的有效安装步骤.

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

最终,我最终遇到了通过 "https://*.com/users/706595/philipd">PhilipD ,它以错误的格式发布,未得到更正.所以问题被删除了.

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.

我在这里重新发布 PhilipD 的答案,这样对于遇到相同问题的人来说,查找起来就更容易了,因为花了半天的时间才发现

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.

这是在Windows Server 2012R2(64位)服务器上,使用IIS作为Web服务器应用程序.但是,我安装了所有与ImageMagick相关的软件的32位版本,因为Web服务器应用程序(IIS)是32位的.以下显示了截至2017年10月的最新/最新版本.

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.

从菜单栏中单击下载"

Click "Download" from the menu bar

  • 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.
  • 转到> http://windows.php.net/downloads/pecl/deps/
  • 选择具有最高版本号的"ImageMagick"程序包
    • *请注意,该版本可能与上面(1.)中的项目
    • 的版本不同.
    • 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

      根据下载方式的不同,这可能是必要的,也可能不是必需的,但是如果需要,您应该始终检查并取消阻止"下载的文件.

      • 右键单击每个文件,然后从弹出菜单中选择属性"
      • 如果属性对话框显示文本此文件来自另一台计算机,并且可能被阻止以保护此计算机"
        • 点击取消阻止"按钮
        • 单击确定".
        • 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.

          如果您不取消阻止"下载的文件,尤其是ZIP文件,则仍可以将已安装或复制的单个文件标记为阻止",这有时会在运行Windows Server 2003时引起一些奇怪的问题.软件.

          • 运行ImageMagick-7.0.7-8-Q16-x86-dll.exe进行安装
          • 接受许可协议
          • 在安装过程中的每个屏幕上接受默认设置.

          安装完成后,要测试安装是否成功,请打开命令提示符并运行以下两个命令:

          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:
          

          这应该显示一个"IMDisplay"窗口,其中显示了在画架上创建蒙娜丽莎肖像的向导的素描/图像.

          This should display an "IMDisplay" window showing a sketch/image of a wizard at an easel creating a Mona Lisa portrait.

          • 解压缩您在步骤3中下载的文件.
          • 进入bin目录
          • IM_MOD_RL_*.dll文件( 125个文件)复制到ImageMagick的已安装版本的文件夹中,例如C:\Program Files (x86)\ImageMagick-7.0.7-Q16
          • 回到bin目录
          • CORE_RL_*.dll文件( 20个文件)复制到已安装的ImageMagick版本的文件夹中,例如C:\Program Files (x86)\ImageMagick-7.0.7-Q16 * *在提示您要覆盖/重命名的情况下,选择覆盖"
            • 注意,这将破坏Imagick的命令版本. magick:JPEG库版本错误:库为80,调用者希望为62
            • 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
              • 解压缩在步骤2中下载的文件.
              • 将文件php_imagick.dll复制到服务器上已安装的PHP版本的"ext"文件夹中,例如C:\php\7.1\ext.
              • 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.

              请勿复制CORE_RL_ *文件
              在网络上的某些文章中,您将看到有关说明,也需要从该工具包中复制CORE_RL_ *文件以替换ImageMagick文件夹中的文件,但这是不正确的.在步骤6中复制了这些文件的相应版本.

              • 在PHP软件文件夹中编辑php.ini文件,例如"C:\ PHP \ 7.1 \ 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
              

            • 重新启动IIS似乎还不够,您需要重新启动整个计算机.这可能与IIS无法识别Imagick输入的PATH条目有关.

              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.

              • 在Web根目录中创建一个PHP文件,其中包含以下内容:

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

          • 在网络浏览器中访问此文件

          • Access this file in a web browser,

            它应该如下所示:

            imagick imagick模块:启用了imagick模块3.4.3版本
            imagick类Imagick,ImagickDraw,ImagickPixel,ImagickPixelIterator,ImagickKernel
            使用ImageMagick版本ImageMagick 6.9.3-7 Q16 x86编译的Imagick 2016年3月27日 http://www.imagemagick.org
            Imagick使用ImageMagick库版本ImageMagick 6.9.3-7 Q16 x86 2016-03-27 http://www.imagemagick.org
            ImageMagick版权所有(C)1999-2015 ImageMagick Studio LLC
            ImageMagick发布日期2016年3月27日
            ImageMagick支持的格式数:216
            ImageMagick支持的格式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,剪切,数据,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,传真,FITS,FPX,分形,FTS,G3,GIF,GIF87,梯度,灰色,GROUP4,GV,H,HALD,HDR,直方图,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,预览,PS,PS2,PS3,PSB,PSD,PTIF,PWP,径向梯度,RAF,RAS,RAW,RGB,RGBA,RGBO,RGF,RLA,RLE,RMF,RW2,SCR,SCREENSHOT,SC T,SFW,SGI,SHTML,SIX,SIXEL,SPARSE-COLOR,SR2,SRF,STEGANO,SUN,TEXT,TGA,THUMBNAIL,TIFF,TIFF64,TILE,TIM,TTC,TTF,TXF,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

            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

            重要提示:
            如果受支持的格式" 部分未显示任何格式,或仅显示了少量格式,则最可能的原因是您错过了复制IM_MOD_RL_ *或CORE_RL_ * DLL的一个或多个文件放入ImageMagick文件夹中,或者您从"php_magick"工具包中复制了它们.

            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.

            在Web根目录中创建一个PHP文件,其中包含以下内容(我从"Verify ImageMagick安装"项中的一项中复制了该文件):

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

            在浏览器中运行此PHP文件.它应该显示包含文本"Hello World!"的图像.

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

            检查php-errors.log文件是否存在任何错误.
            您可以在php.ini文件中找到php-errors.log文件的定义位置.检查此文件中是否有与ImageMagick安装相关的最新错误.

            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文件需要Ghostscript
            在安装并设置完上述所有内容之后,ImageMagick可以在PHP中用于转换图像,但不能用于将PDF文件转换为图像.对于最后一步,似乎也有必要从 https://www安装Ghostscript. ghostscript.com/download/gsdnld.html ,只有在我安装了64位版本的Ghostscript的情况下,它才能正确运行(即使我安装的其他所有版本都是32位版本).仅需安装Ghostscript.无需更改php.ini或任何其他配置.

            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.