How To install ImageMagick PHP extension in XAMPP on Windows?

How To install ImageMagick PHP extension in XAMPP on Windows?

Here’s a step-by-step guide on how to install ImageMagick PHP extension in XAMPP on Windows:

Download the correct Imagick DLL

Go to the PECL Imagick extension page
Download the version that matches:

  • Your PHP version (e.g. PHP 8.2, 8.1, etc.)
  • Your PHP architecture (x64 or x86 — check using phpinfo() or php -i)
  • Thread safety: TS (Thread Safe) if you’re using Apache with XAMPP (most common), or NTS (Non-Thread Safe) if you’re using FastCGI

Example file: php_imagick-3.8.0-8.2-ts-vs16-x64.zip

Copy the DLL to XAMPP

  1. Extract the downloaded file php_imagick-3.8.0-8.2-ts-vs16-x64.zip
  2. Extract php_imagick.dll and save it to the ext directory of your PHP installation
  3. Copy this file to your XAMPP php\ext directory:
C:\xampp\php\ext\php_imagick.dllCode language: CSS (css)

Also extract from php_imagick-….zip the other DLL files (they may start with CORE_RL, FILTER, IM_MOD_RL, or ImageMagickObject depending on the version), and save them to the PHP root directory (where you have php.exe), or to a directory in your PATH variable

C:\xampp\php\

Update php.ini

Open your php.ini file:

C:\xampp\php\php.iniCode language: CSS (css)

Add the following line at the end of the file:

extension=imagick

Save the file

Verify Installation

  • Create a PHP file, for example phpinfo.php: phpCopyEdit<?php phpinfo(); ?>
  • Open this in your browser: http://localhost/phpinfo.php
  • Look for imagick section — if you see it, the extension is installed correctly.
PHP 8.2.12 phpinfo imagick

To test if the extension works, you can run this PHP code:

Here’s a simple test script to verify if ImageMagick is installed and working properly in your XAMPP setup:

<?php
try {
    // Check if Imagick class exists
    if (!class_exists('Imagick')) {
        die("Imagick class not found. Extension may not be installed.");
    }

    // Create a new Imagick object
    $image = new Imagick();
    
    // Create a simple 200x200 red image
    $image->newImage(200, 200, new ImagickPixel('red'));
    $image->setImageFormat('png');
    
    // Add some text
    $draw = new ImagickDraw();
    $draw->setFillColor(new ImagickPixel('white'));
    $draw->setFontSize(20);
    $draw->annotation(20, 100, 'ImageMagick Works!');
    $image->drawImage($draw);
    
    // Set the appropriate header and output the image
    header('Content-Type: image/png');
    echo $image;
    
    // Destroy the image to free memory
    $image->destroy();
    
} catch (Exception $e) {
    // Display any errors
    header('Content-Type: text/plain');
    echo "ImageMagick Test Failed:\n";
    echo "Error: " . $e->getMessage() . "\n";
    echo "Check if:\n";
    echo "1. ImageMagick is installed on your system\n";
    echo "2. PHP Imagick extension is properly installed\n";
    echo "3. The correct paths are set in your environment variables\n";
}
?>Code language: HTML, XML (xml)

How to use this test script:

  1. Save this code as test_imagick.php in your XAMPP htdocs folder
  2. Access it through your browser: http://localhost/test_imagick.php

Expected results:

  • If ImageMagick is working, you’ll see a red square with white text saying “ImageMagick Works!”
ImageMagick Works
  • If there are problems, you’ll see an error message explaining what might be wrong

This script tests:

  • The existence of the Imagick class
  • Basic image creation capabilities
  • Text rendering functionality
  • Proper output of the image

If this works, you can be confident that ImageMagick is properly installed and functional in your XAMPP environment.

Lalit Kumar Dudeja

Introduction:Hi, I'm Lalit

Full-time Freelance WordPress Developer based in Delhi, India. Founder of BloggingStep.com. I help businesses with WordPress Development, eCommerce, Speed Optimization, and more.

Hire Me
Lalit Kumar Dudeja

Lalit Kumar Dudeja

Delhi, India

You can follow him:

About the Author


Lalit Kumar Dudeja is a founder of Bloggingstep.com. He is full-time freelance WordPress developer, blogger and affiliate marketer. His aim to setup this blog is to help people learn about WordPress, blogging, affiliate marketing and make money online by sharing his experiences of his online journey till now. During his free time, he likes to improve his web development skills and love to travel with his family members.

Related Posts