• Installing Imagick for PHP 8 on Windows 10

    Installing Imagick for PHP 8 on Windows 10

    Here are some instructions for installing Imagick for PHP 8 on Windows 10.

    If you’re running PHP 8 on Windows and you want to use the Imagick PHP extension then you may want to refer to this post for some download and installation instructions.

    Background

    In 2016 I had a need for the Imagick PHP Extension to correct the orientation of images uploaded to WordPress. Finding that the installation wasn’t a doddle, I wrote a blog post entitled Installing Imagick for PHP 7 on Windows 10. It appears that this post is quite popular. 6 years later on I’ve decided that it might be a good idea to write a more up to date post. This time it’s for PHP 8.0 and Windows 10; it may also work on Windows 11.

    The secret to the installation was finding the correct hint for the location of the ImageMagick binary files upon which the Imagick PHP extension is dependent.

    I hope that you’ll find these notes to be useful.

    Overview

    • Imagick is a native PHP extension to create and modify images using the ImageMagick API.
    • It provides a DLL that you need to install as an extension to your PHP installation.

    For my PHP 8 installation…

    • I followed my own instructions and picked the versions I needed for my current version of PHP.
    • I had to modify the instructions slightly.
    • I didn’t have as many problems.
    • It appears you no longer need to install ImageMagick for the Imagick PHP extension to work.

    Installation

    • Determine your version of PHP, whether or not it’s Thread Safe, and the architecture.
    • Download the Imagick extension you need.
    • Extract the .dll files from the Imagick extension zip file.
    • Change php.ini to enable the php_imagick extension.
    • Reboot.
    • Test.

    If you want to be able to use ImageMagick’s programs, such as IMDisplay.exe

    • Download the compatible version of ImageMagick.
    • Install ImageMagick to a directory of your choice.
    • Set the environment to enable the ImageMagick DLLs to be found.

    Determine your version of PHP

    Use php -i to run phpinfo() and look at the first few lines of the output

    phpinfo()
    PHP Version => 8.0.2
    
    System => Windows NT SB 10.0 build 19043 (Windows 10) AMD64
    Build Date => Feb  3 2021 18:29:02
    Build System => Microsoft Windows Server 2016 Standard [10.0.14393]
    Compiler => Visual C++ 2019
    Architecture => x64
    ...
    Debug Build => no
    Thread Safety => enabled
    Thread API => Windows Threads
    ...

    Download the Imagick extension you need

    Extract the .dlls from the Imagick extension .zip file

    Since PHP extensions are loaded dynamically, you need to tell PHP where to find them. It doesn’t use the PATH for this. You either need to fully qualify the file name or define the extension_dir directive.

    For php_imagick.dll to be loadable all the DLLs upon which it is statically dependent also need to be accessible.

    When ImageMagick is installed then you will be using its DLLs. In the mean time you need to extract all of them, ensuring that they are in a directory that’s in your PATH.

    You have several options:

    • Copy the files into a directory that’s already in your PATH,
    • add the directory to your PATH,
    • or both.

    I chose to install all the .dll files into C:\Imagick and added that directory to my PATH, after the entry for C:\php.

    Change php.ini to enable the php_imagick extension

    Determine the directory for extensions by checking for the extension_dir directive in your phpinfo output.

    ...
    Directive => Local Value => Master Value
    ...
    extension_dir => C:\php\ext => C:\php\ext
    ...

    If the top level directory doesn’t match that from which PHP is run then you should either correct the local value or fully qualify the file name of the extension.

    Since I’d extracted the DLLs into C:\Imagick, I fully qualified the entry in the php.ini file.

    extension=c:\Imagick/php_imagick.dll

    Reboot

    Rebooting is the simplest way of ensuring that your system notices the changes you have made.

    If you’re just running PHP from the Command Prompt you should be able to get away with closing one and opening a new Command Prompt.

    Or you may choose to use ApacheMonitor to stop and restart your web server. But this may not pick up system environment changes.

    Test

    • Check your phpinfo() output shows a non-zero value for ImageMagick number of supported formats. You should see something like this
    ImageMagick number of supported formats:  => 263
    • Also test phpinfo from your browser. Expect the same result.
    • Try some code.

    Test in WordPress Site Health

    Use the WordPress Site Health tool ( Dashboard > Tools > Site Health > Info tab ) to confirm the Active editor for Media Handling.

    Active editor: GD

    Initially, before installing Imagick, the value could be WP_Image_Editor_GD.

    Active editor: Imagick

    With Imagick correctly configured the Active editor becomes WP_Image_Editor_imagick.

    Download the compatible version of ImageMagick

    With the extension installed it is now possible to determine the version of ImageMagick upon which php_imagick.dll is dependent.

    Run php -i and check the output.

    imagick
    
    imagick module => enabled
    imagick module version => 3.7.0
    imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
    Imagick compiled with ImageMagick version => ImageMagick 7.1.0-18 Q16 x64 2021-12-14 https://imagemagick.org
    Imagick using ImageMagick library version => ImageMagick 7.1.0-18 Q16 x64 2021-12-14 https://imagemagick.org
    ImageMagick copyright => (C) 1999-2021 ImageMagick Studio LLC
    ImageMagick release date => 2021-12-14
    ImageMagick number of supported formats:  => 263
    ImageMagick supported formats => 3FR, 3G2, 3GP, AAI, AI, APNG, ART, ARW, ASHLAR, AVI, AVIF, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CLIPBOARD, CMYK, CMYKA, CR2, CR3, CRW, CUBE, CUR, CUT, DATA, DCM, DCR, DCRAW, DCX, DDS, DFONT, DJVU, DNG, DOT, DPS, DPX, DXT1, DXT5, EMF, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FARBFELD, FAX, FF, FILE, FITS, FL32, FLIF, FLV, FPX, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, HALD, HDR, HEIC, HEIF, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, JXL, K25, KDC, KERNEL, LABEL, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORA, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PHM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGB565, RGBA, RGBO, RGF, RLA, RLE, RMF, RSVG, RW2, SCR, SCREENSHOT, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TM2, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMF, WMV, WPG, X3F, XBM, XC, XCF, XPM, XPS, XV, YAML, YCbCr, YCbCrA, YUV
    
    Directive => Local Value => Master Value
    imagick.allow_zero_dimension_images => 0 => 0
    imagick.locale_fix => 0 => 0
    imagick.progress_monitor => 0 => 0
    imagick.set_single_thread => 1 => 1
    imagick.shutdown_sleep_count => 10 => 10
    imagick.skip_version_check => 0 => 0

    The version of ImageMagick you will need is shown in “Imagick compiled with ImageMagick version”.

    Now you won’t find what you’re looking for at www.imagemagick.org.
    You need to go to https://windows.php.net/downloads/pecl/deps/

    The file I downloaded was ImageMagick-7.1.0-18-vc15-x64.zip

    Install ImageMagick to a directory of your choice

    • Extract the whole of the bin directory from the ImageMagick zip file to a directory of your choice. I chose C:\ImageMagick\bin.

    Set the environment to enable the ImageMagick DLLs to be found

    Use “Edit the system environment variables” to edit the System variables section.

    • From the command prompt run SystemPropertiesAdvanced.
    • Add an entry to the PATH for ImageMagick ensuring it is before the entry for the PHP extensions.
    • Add an entry for MAGICK_HOME setting it to the ImageMagick home directory.

    Basic problem determination

    If you get the following when running php -i

    Warning: PHP Startup: Unable to load dynamic library 'C:\Imagick/php_imagick.dll' 
    (tried: C:\Imagick/php_imagick.dll (The specified module could not be found), 
    C:\php\ext\php_C:\Imagick/php_imagick.dll.dll (The specified module could not be found)) 
    in Unknown on line 0

    then you will need to make sure the dependent DLLs are correctly installed.

    In phpinfo output, if you do not have the correct version of ImageMagick installed and configured then you will probably see

    ImageMagick number of supported formats: => 0
    ImageMagick supported formats =>

    Summary of downloads

    Component URL Version required
    PHP 8.0.18 is the latest version https://windows.php.net/download/ VS16 x64 Non Thread Safe (2022-Apr-13 08:25:56)
    php-8.0.18-nts-Win32-vs16-x64.zip
    Imagick extension https://windows.php.net/downloads/pecl/releases/imagick/ php_imagick-3.7.0-8.0-ts-vs16-x64.zip
    ImageMagick runtime https://windows.php.net/downloads/pecl/deps/ ImageMagick-7.1.0-18-vc15-x64.zip
    Summary of downloads for Imagick and ImageMagick

    My local installation

    Directory/File Contains
    C:\php PHP 8.0.2 thread safe x64
    C:\php\php.ini PHP Configuration file
    C:\php\ext PHP extensions.
    C:\Imagick php_imagick.dll and associated files (.DLL and .PDB)
    C:\ImageMagick\bin ImageMagick runtime. This folder includes the same DLLs as in C:\Imagick with the exception of php_imagick.dll

    Environment variables

    Variable Purpose Contents
    PATH System path Includes C:\ImageMagick\bin, C:\php, C:\php\ext and C:\Imagick in that order
    MAGICK_HOME ImageMagick home C:\ImageMagick\bin
    Environment variables for ImageMagick

    References

    See also Installing Imagick for PHP 7 on Windows 10



    Published:

    Last updated:

    April 16, 2022

Categories

Tide times from tidetimes.org.uk

Tide Times & Heights for Langstone Harbour on
4th December 2023
03:48 High Tide ( 4.09m )
08:48 Low Tide ( 2.03m )
15:46 High Tide ( 3.84m )
21:15 Low Tide ( 1.91m )

Tide times from tidetimes.org.uk

Tide Times & Heights for Northney on
4th December 2023
04:09 High Tide ( 3.96m )
09:06 Low Tide ( 1.86m )
16:13 High Tide ( 3.74m )
21:39 Low Tide ( 1.7m )