When building your website, some PHP web applications including WordPress and Laravel may require the additional ImageMagick PHP extension for advanced image processing.
RunCloud does support the ImageMagick PHP extension, but it is not enabled by default.
In this post, we will discuss about how to install ImageMagick PHP Extension (Imagick) for your PHP web application.
What is ImageMagick
ImageMagick is a free and open-source software that was created in 1987 by John Cristy to create, edit, compose, or convert bitmap images.
It can read and write over 200 image formats, including PNG, JPEG, GIF, HEIC, TIFF, DPX, EXR, WebP, Postscript, PDF, and SVG.
You can use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
ImageMagick vs GD Library
ImageMagick is not the only image optimization library in PHP application.
GD is another library that is also very popular and it is automatically available in RunCloud server.
Both ImageMagick and GD Library can be used for:
- Resize / crop images
- Apply filters to image, for example color, contrast, brightness, etc.
- Adding content to image, for example text, shape, other image (watermark), etc.
- Compress images
- Convert images to different file types
The key differences between ImageMagick and GD library are:
- ImageMagick supports over 200 image formats
- ImageMagick usually produces better quality images, although sometimes better quality image will also increase the image file size
- GD is widely available and usually enabled by default, but you have install and enable ImageMagick
Installing ImageMagick PHP Extension (Imagick)
For example, when using WordPress, we might want to use the ImageMagick Engine WordPress Plugin to improve the quality of image for processing resizing and cropping in WordPress using ImageMagick.
When ImageMagick is not installed on our server, we will see “ImageMagick PHP module not found” warning on this plugin setting page.
Before installing ImageMagick, ensure the proper PHP version for your web application.
Depending on the PHP version installed, you will need a different ImageMagick installation. But once you have installed it, it will be available for all web applications which use the same PHP version on your server.
Let’s start with the PHP 8.1 Imagick PHP module.
PHP 8.1 Imagick PHP Module
Please login to your server as a root user using Terminal (Mac OSX / Linux) or Powershell / Putty (Windows).
ssh root@<youripaddress>
After you have logged in to your server, please run this command to install ImageMagick PHP extension for PHP 8.1 on this server.
apt-get install php81rc-pecl-imagick
After you have installed ImageMagick successfully, you will need to reload the PHP-FPM in your server by running this command.
systemctl reload php81rc-fpm
If you want to check / verify that ImageMagick is installed and activated, you can run this command:
/RunCloud/Packages/php81rc/bin/php -i | grep imagemagick
If ImageMagick has been installed correctly, it will be not empty, for example.
After installing ImageMagick correctly, you can see the warning disappear in ImageMagick Engine WordPress Plugin.
PHP 8.0 Imagick PHP Module
If your website uses PHP 8.0, please log in to your server as the root user to install ImageMagick by running this command, similar to ImageMagick installation for PHP 8.1 above.
# login to your server using root
ssh root@<youripaddress>
# install imagick module
apt-get install php80rc-pecl-imagick
# reload PHP-FPM
systemctl reload php80rc-fpm
# check / verify if imagick is installed
/RunCloud/Packages/php80rc/bin/php -i | grep imagemagick
PHP 7.4 Imagick PHP Module
If your website uses PHP 7.4, please log in to your server as the root user to install ImageMagick by running this command, similar to ImageMagick installation for PHP 8.1 above.
# login to your server using root
ssh root@<youripaddress>
# install imagick module
apt-get install php74rc-pecl-imagick
# reload PHP-FPM
systemctl reload php74rc-fpm
# check / verify if imagick is installed
/RunCloud/Packages/php74rc/bin/php -i | grep imagemagick
PHP 7.3 Imagick PHP Module
If your website uses PHP 7.3, please log in to your server as the root user to install ImageMagick by running this command, similar to ImageMagick installation for PHP 8.1 above.
# login to your server using root
ssh root@<youripaddress>
# install imagick module
apt-get install php73rc-pecl-imagick
# reload PHP-FPM
systemctl reload php73rc-fpm
# check / verify if imagick is installed
/RunCloud/Packages/php73rc/bin/php -i | grep imagemagick
PHP 7.2 Imagick PHP Module
If your website uses PHP 7.2, please log in to your server as the root user to install ImageMagick by running this command, similar to ImageMagick installation for PHP 8.1 above.
# login to your server using root
ssh root@<youripaddress>
# install imagick module
apt-get install php72rc-pecl-imagick
# reload PHP-FPM
systemctl reload php72rc-fpm
# check / verify if imagick is installed
/RunCloud/Packages/php72rc/bin/php -i | grep imagemagick
PHP 7.1 Imagick PHP Module
If your website uses PHP 7.1, please log in to your server as the root user to install ImageMagick by running this command, similar to ImageMagick installation for PHP 8.1 above.
# login to your server using root
ssh root@<youripaddress>
# install imagick module
apt-get install php71rc-pecl-imagick
# reload PHP-FPM
systemctl reload php71rc-fpm
# check / verify if imagick is installed
/RunCloud/Packages/php71rc/bin/php -i | grep imagemagick
PHP 7.0 Imagick PHP Module
If your website uses PHP 7.0, please log in to your server as the root user to install ImageMagick by running this command, similar to ImageMagick installation for PHP 8.1 above.
# login to your server using root
ssh root@<youripaddress>
# install imagick module
apt-get install php70rc-pecl-imagick
# reload PHP-FPM
systemctl reload php70rc-fpm
# check / verify if imagick is installed
/RunCloud/Packages/php70rc/bin/php -i | grep imagemagick
PHP 5.6 Imagick PHP Module
If your website uses PHP 5.6, please log in to your server as the root user to install ImageMagick by running this command, similar to ImageMagick installation for PHP 8.1 above.
# login to your server using root
ssh root@<youripaddress>
# install imagick module
apt-get install php56rc-pecl-imagick
# reload PHP-FPM
systemctl reload php56rc-fpm
# check / verify if imagick is installed
/RunCloud/Packages/php56rc/bin/php -i | grep imagemagick
Note: PHP5.6 is only available when you use Ubuntu 16.04 LTS in your RunCloud server.
Optional: Adding PDF Support To ImageMagick
If you want to allow ImageMagick to process PDF files, you will have to login as root user again to your server and edit policy.xml
.
For example, you can use nano
to edit this file by running this command.
nano /etc/ImageMagick-6/policy.xml
Then please scroll down and locate this line.
<policy domain="coder" rights="none" pattern="PDF" />
You need to disable it by commenting out that line. For example, you can replace that line by following line.
<!-- <policy domain="coder" rights="none" pattern="PDF" /> -->
Please save the file and exit the editor.
Then reload the PHP-FPM again, for example for PHP 7.4 you can run this command again.
systemctl reload php74rc-fpm
NOTE: Please be careful when you enable PDF support for Imagick. Make sure you always use it with trusted PDF files.
Using ImageMagick in WordPress
WordPress supports both ImageMagic and GD Library for PHP image processing extensions to resize and crop images in your website.
By default, WordPress will try to use ImageMagick. If it is not available or it doesn’t support the requested mime-type, WordPress will use the GD extension.
If you need more control of the quality of re-sized images, you can use ImageMagick Engine WordPress Plugin.
Image Watermark WordPress plugin is another cool plugin that allows you to watermark each image that you upload to your WordPress site using Imagick.
If you enable PDF support for the Imagick PHP extension, you will get one extra bonus, WordPress will automatically generate an image for each PDF you upload to your WordPress site!
Using ImageMagick in Laravel
If you use Laravel for your website, these are some libraries for you.
Intervention Image is an open-source PHP image handling and manipulation library. It provides an easier and more expressive way to create, edit, and compose images and supports currently the two most common image processing libraries GD Library and Imagick. It is Laravel friendly.
This library provides an easy to work with the class to convert PDF files to images using Imagick and Ghostscript.
Summary
In this post, we show you a complete guide on how to install the ImageMagick PHP extension (Imagick) for your website (web application) in RunCloud.
Are you using ImageMagick for your image processing on your website? Do not hesitate to share your experience with us.
Categories: Tutorials, Laravel, Tips & Tricks, WordPress
Kudos for this to the point guide.
Thank you!
I use one server for two sites. Can a different version of PHP be created on one server?
YES!
In RunCloud, you can have multiple websites (web applications) in one server.
And you can use different PHP version for each website (web application).
Also, you can change the PHP version of your website anytime from Web Application Settings page.
Assuming that you’re running multiple versions of PHP for different web applications, you will simply need to install the different versions of ImageMagick for each PHP version you’re running? Any configuration needed?
Hi Ryan,
Yes, you only need to repeat the process for each PHP version that you are using on your web applications. No extra configuration needed.
Anyone who is having trouble installing it, You need to add sudo before the first and 2nd command like this “sudo apt-get install php74rc-pecl-imagick”.