ImageMagick is a powerful image manipulation library that can handle various image formats and operations, including rotation (Check here). In this comprehensive guide, we will walk you through the steps to manually install and configure ImageMagick, a powerful image manipulation library, and its PHP extension Imagick on a XAMPP server. Whether you're a web developer or an enthusiast looking to enhance your server's image processing capabilities, this tutorial covers everything you need to know from downloading and installing the necessary files to verifying the installation. With step-by-step instructions and detailed explanations, you'll learn how to properly configure your PHP environment to handle various image formats and operations, ensuring seamless integration with your XAMPP setup. Get ready to unlock the full potential of ImageMagick for your projects!
Process to Install ImageMagic Library in system:
For Linux/Unix
sudo apt-get update
sudo apt-get install imagemagick
sudo apt-get install php-imagick
For Windows (Using XAMPP)
Download the ImageMagick binary from the official website.
To install ImageMagick and the ImageMagick PHP extension (Imagick) on Windows with XAMPP, follow these steps:
Step 1: Download and Install ImageMagick
- Go to the ImageMagick download page.
- Download the Windows binary release suitable for your system (e.g.,
ImageMagick-7.1.1-44-Q16-HDRI-x64-dll.exe
). - Run the installer and follow the installation instructions. Make sure to check the option to add ImageMagick to the system PATH during installation.
Step 2: Download and Install the Imagick PHP Extension
- Go to the PECL Imagick extension page.
- Download the appropriate DLL file for your PHP version and architecture (e.g.,
php_imagick-3.4.4-7.3-ts-vc15-x64.zip
for PHP 7.3, thread-safe, VC15, x64).
To choose the correct DLL for your PHP version, you need to match the following criteria in the php.ini
file in C://xampp/php/php.ini
:
Thread Safety
Check if your PHP installation is Thread Safe (TS) or Non-Thread Safe (NTS). You can find this information in your phpinfo()
output. Look for "Thread Safety" in the output:
- If it says "enabled," you need the Thread Safe (TS) version.
- If it says "disabled," you need the Non-Thread Safe (NTS) version.
Architecture
Determine if your PHP installation is 32-bit (x86) or 64-bit (x64). This is also available in the phpinfo()
output. Look for "Architecture" or "Compiler":
- If it mentions x64, you need the 64-bit version.
- If it mentions x86, you need the 32-bit version.
Based on your PHP version (PHP 8.2.12), you should choose the appropriate DLL from the following options:
- 8.2 Non Thread Safe (NTS) x64: If your PHP is Non-Thread Safe and 64-bit.
- 8.2 Thread Safe (TS) x64: If your PHP is Thread Safe and 64-bit.
- 8.2 Non Thread Safe (NTS) x86: If your PHP is Non-Thread Safe and 32-bit.
- 8.2 Thread Safe (TS) x86: If your PHP is Thread Safe and 32-bit.
Make sure to download the correct DLL Zip that matches your PHP configuration.
- Extract the DLL file (
php_imagick.dll
) from the ZIP archive. - Copy the
php_imagick.dll
file to theext
directory of your PHP installation (e.g.,C:\xampp\php\ext
).
When you download the Imagick extension, it comes as a ZIP file containing multiple files, including the php_imagick.dll
file. Here's how to proceed:
Extract the ZIP File
Use a tool like WinRAR or 7-Zip to extract the contents of the ZIP file.
Locate the DLL File
Inside the extracted folder, find the php_imagick.dll
file.
Copy DLL Files
There might be other DLL files in the extracted folder that Imagick depends on. Copy these files to the main PHP directory (e.g., C:\xampp\php
).
You can create a dedicated folder inside the PHP directory for Imagick-related files to keep your XAMPP installation organized. Here's how you can do it:
Steps:
- Create a New Folder: Inside your PHP directory (e.g.,
C:\xampp\php
), create a new folder namedimagick
. - Copy DLL Files: Copy the required core ImageMagick DLLs (e.g.,
CORE_RL_*
,IM_MOD_RL_*
) into the newimagick
folder. Copy thephp_imagick.dll
file to theext
directory (e.g.,C:\xampp\php\ext
).
Update php.ini
:
- Open your
php.ini
file located in your XAMPP installation directory (e.g.,C:\xampp\php\php.ini
). - Add the following line to enable the Imagick extension:
extension=imagick
- Add the new Imagick folder to the PHP PATH within the
php.ini
:[PHP] ; Directory in which the loadable extensions (modules) reside. extension_dir = "C:\xampp\php\ext" ; Add Imagick folder to the PHP PATH env[Path] = "C:\xampp\php\imagick;${env[Path]}"
Restart Apache:
- Open the XAMPP Control Panel.
- Stop the Apache server.
- Start the Apache server again.
Verify Installation:
- Create an
info.php
file in your XAMPPhtdocs
directory and add the following code to verify that the Imagick extension is enabled:<?php phpinfo(); ?>
- Open
http://localhost/info.php
in your browser and look for the "imagick" section. This section should confirm that the Imagick extension is enabled.
Once you have completed these steps, the Imagick extension should be installed and enabled in your XAMPP environment. You can then use the Imagick functions in your PHP scripts to handle image rotation and other image manipulation tasks.
Check our latest blog at Fixing image rotation using Javascript and PHP with Imagick (ImageMagick Library).
Leave a Reply