How To Install ImageMagick PHP Extension (Imagick)

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.

runcloud-imagemagick-01-imagick-php-module-not-found2

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 PHP7.4 Imagick PHP module.

PHP7.4 Imagick PHP Module

Please login to your server as 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 PHP7.4 on this server.

apt-get install php74rc-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 php74rc-fpm

If you want to check / verify that ImageMagick is installed and activated, you can run this command:

/RunCloud/Packages/php74rc/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.

PHP7.3 Imagick PHP Module

If your website uses PHP7.3, please login to your server as root user to install ImageMagick by running this command, similar with ImageMagick installation for PHP7.4 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

PHP7.2 Imagick PHP Module

If your website uses PHP7.2, please login to your server as root user to install ImageMagick by running this command, similar with ImageMagick installation for PHP7.4 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

PHP7.1 Imagick PHP Module

If your website uses PHP7.1, please login to your server as root user to install ImageMagick by running this command, similar with ImageMagick installation for PHP7.4 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

PHP7.0 Imagick PHP Module

If your website uses PHP7.0, please login to your server as root user to install ImageMagick by running this command, similar with ImageMagick installation for PHP7.4 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

PHP5.6 Imagick PHP Module

If your website uses PHP5.6, please login to your server as root user to install ImageMagick by running this command, similar with ImageMagick installation for PHP7.4 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 PHP7.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 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 allow you to watermark each image that you upload to your WordPress site using Imagick.

If you enable PDF support for 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

Intervention Image is an open source PHP image handling and manipulation library. It provides an easier and 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.

Convert a pdf to an image

This library provides an easy to work with class to convert PDF files to images using Imagick and Ghostscript.

Summary

In this post, we show you complete guide on how to install ImageMagick PHP extension (Imagick) for your website (web application) in RunCloud.

Are you using ImageMagick for your image processing in your website? Do not hesitate to share your experience with us.

Simplifying Server Management

RunCloud is a cloud server management tool that allows you to maintain full control of your server and host multiple WordPress, WooCommerce, Laravel, and PHP applications with fast and easy configuration.

Start Your Free Trial

5 days free trial no credit card required cancel anytime

5 thoughts on “How To Install ImageMagick PHP Extension (Imagick)

    1. 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.

  1. 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?

Leave a Comment

Your email address will not be published. Required fields are marked *