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

后端 未结 2 1054
忘了有多久
忘了有多久 2020-12-20 09:13

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

2条回答
  •  误落风尘
    2020-12-20 09:23

    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.

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

提交回复
热议问题