如何在 windows 服务器上安装用于 IIS 服务器的 ImageMagick php 扩展

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

我有一个 windows 网络服务器 2012r2 并希望在其上安装 Imagemagick php 扩展,但是 everything I've tried 未能在 [=17= 中显示它]信息()。

如何获得 imagemagick 运行?我找不到 IIS 的有效安装步骤。

最终我得到了一个 blogpost, which is a repost of a deleted post by PhilipD,它以错误的格式发布并且没有更正。所以这个问题被删除了。

我正在重新发布 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 的有效答案。这些步骤详细说明了 32 位安装。我为我的 64 位 php.

安装了 64 位

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

1。下载 ImageMagick 安装程序

2。下载 ImageMagick

的 php 模块

3。将 PHP 的依赖包下载到 load/use ImageMagick

4。解锁每个下载的文件

这可能是必要的,也可能不是必要的,具体取决于您下载它的方式,但您应该始终检查并 "unblock" 下载文件(如果需要)。

  • 右键单击每个文件,然后select弹出菜单中的“属性”
  • 如果属性对话框显示文本 “此文件来自另一台计算机,可能会被阻止以帮助保护此计算机”
    • 单击“取消阻止”按钮
    • 点击确定。

如果您不“取消阻止”下载的文件,尤其是 ZIP 文件,安装或复制的单个文件仍会被标记为“已阻止”,这有时会导致一些奇怪的情况运行安装软件时出现问题。

5。安装 Imagick 应用程序

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

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

magick wizard: wizard.jpg
magick wizard.jpg win:

这应该显示一个 "IMDisplay" window 显示 sketch/image 在画架上创作蒙娜丽莎肖像的巫师。

6.安装依赖项

  • 解压缩您在第 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 * * 如果出现提示您希望 overwrite/rename、select 覆盖
    • 注意,这会破坏 Imagick 的命令版本。 magick:错误的 JPEG 库版本:库是 80,调用者期望 62

7。安装 Imagick php 扩展 dll

  • 解压步骤 2 中下载的文件。
  • 将文件php_imagick.dll复制到服务器上PHP安装版本的"ext"文件夹,例如C:\php.1\ext.

不要复制 CORE_RL_* 文件
在网络上的一些文章中,您会看到说明还从该工具包中复制 CORE_RL_* 文件以替换 ImageMagick 文件夹中的文件,但这是不正确的;这些文件的适当版本已在步骤 6 中复制。

8。修改PHP.ini

  • 编辑php.ini软件文件夹下的php.ini文件,如“C:\PHP.1\php.ini”
  • 将以下行添加到包含其他扩展名的部分:

       extension=php_imagick.dll
    

9。重新启动服务器。

重启IIS好像不行,需要重启整台机器。这可能与 IIS 无法识别 Imagick 输入的 PATH 条目有关。

10。测试 PHP信息

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

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

  • 搜索 PHPINFO 输出中现在应该存在的“Imagick”部分。

它应该如下所示:

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

重要提示:
如果 “支持的格式” 部分未显示任何格式,或仅显示少量格式,则最可能的原因是您错过了 [=236] 中的一种或多种复制=]* 或 CORE_RL_* DLL 文件到 ImageMagick 文件夹中,或者您从“php_magick”工具包中复制它们。

11。在 PHP

中使用 ImageMagick 测试图像生成

在 Web 根目录中创建一个 PHP 文件,其中包含以下内容(我从此项验证 ImageMagick 安装的条目之一中复制了它):

<?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!".

的图像

12。检查错误

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

PDF 文件需要 Ghostscript
安装并设置以上所有内容后,ImageMagick 可以在 PHP 中用于转换图像,但不能用于将 PDF 文件转换为图像。对于这最后一步,似乎还需要安装 Ghostscript - 来自 https://www.ghostscript.com/download/gsdnld.html 并且只有在我安装 64 位版本的 Ghostscript 时它才能正常工作(即使我安装的其他所有内容都是 32 位版本).只需安装 Ghostscript 即可;无需更改 php.ini 或任何其他配置。

更新已接受的答案。环境是 FastCGIModule 的 Win 7 32 位、IIS 7.5、PHP 7.2(线程安全)。 Wordpress 5.5.3 支持 imagick 模块。注意:如果您的代码需要 imagick,截至 2020 年底,最新的非 rc pecl 包是 php_imagick-3.4.4-7.4,其 php_imagick.dll 不适用于 php 8.0。

发现不需要 PHP 的 'dependencies' 包。这意味着 imagemagick 没有被 php 依赖项破坏,因此它对 windows 用户和 PHP 类似的用户仍然可行。

1。为 windows

获取 ImageMagick

https://imagemagick.org/script/download.php#windows 下载 windows ImageMagick-...-x##-dll.exe 的动态变量。 x## 取决于您的系统。 仅供参考,这里测试了ImageMagick-7.0.10-43-Q16-x86-dll.exe

2。获取 php_imagick 模块

https://windows.php.net/downloads/pecl/releases/imagick/ 下载与 php 安装的 'Thread Safety' 匹配的最新 imagick pecl 包。在 phpinfo 输出中找到 'Thread Safety'。避免发布候选包,即名称中带有 'rc#' 的包。作为参考,这里测试了php_imagick-3.4.4-7.2-ts-vc15-x86.zip线程安全版本。明显的共识是在 IIS 上使用非线程安全 php 产品,但两者似乎都有效。 IIS 在内部禁用 php 的线程管理并使用它自己的。这个 40mb 存档中唯一使用的文件是 220kb php_imagick.dll。跳过 3.

4。解锁下载

打开它们的属性,如果 'Unblock' 按钮出现,请单击它。

5。为 windows

安装 Imagemagick

运行 exe 并且不要接受所有默认值,后果自负。安装向导将更新 PATH 环境变量,允许 php 命令在系统重启后到达 imagick 安装。我听到那些窃笑声。

6。 PHP 不需要依赖项

关于 vanilla Imagemagick 安装,CORE_RL_.dll 在根目录中,而 IM_MOD_RL_.dll 文件在其他安装中引用作为 php 依赖项的说明位于 root/modules/coders/ 目录中。为什么不在覆盖 150 多个 dll 并破坏原始安装之前在原始安装上尝试 php?改变了什么,或者什么时候改变是未知的,但 php_magick.dll 和 magick.exe 似乎都乐于分享原始安装。换句话说,命令行上的 imagick 仍然有效。在另行通知之前,'dependencies' 不被视为此类。

7。 & 8.安装php_imagick模块

从 zip 存档中提取 php_imagick.dll 到 php 扩展目录。将行 "" 添加到由 PHP.

解析的 php.ini

9。 & 10. 通过PHP

确认imagick模块加载

如果在为 windows 安装 Imagemagick 后还没有重新启动,请重新启动。或者,在 phpinfo() 输出中查找 'imagick' 的条目。

11。给我看一张图片

从 cmdline 快速测试

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

一个php imagick 例子
我撒了谎;使用模块 zip 中的第二个文件。将 examples/polygon.php 提取到您的站点,然后浏览至 polygon.php 以确认 imagick 模块的某些功能。

我在这里为那些只需要简单测试的人提供了一个精简版。

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