fbpx

How to Install the PHP ImageMagick Extension

Install the PHP ImageMagick Extension

Some web PHP applications, such as WordPress and Laravel, may require the additional PHP ImageMagick extension when developing a website. Imagick PHP is a PHP extension for image processing.

All CMSs support the ImageMagick PHP extension; however, it is deactivated by default.

We’ll go through how to install imagemagick PHP Extension or Imagick PHP for PHP web applications in this article.

What is ImageMagick?

ImageMagick is an open-source free software program created back in 1987 by John Cristy. PHP ImageMagick is used to create, compose, edit, or convert bitmap images.

The software can write and read over 200 image formats, including JPEG, GIF, PNG, TIFF, HEIC, DPX, WebP, EXR, Postscript, PDF, and SVG.

You can apply Imagick WordPress to flip, mirror, resize, rotate, shear, distort, and transform images. You can also adjust image colors, apply different effects, or draw lines, text, polygons, ellipses, and Bézier curves.

How to Install Imagemagick

If you are using WordPress, you may need to use the Imagick WordPress plugin to improve the overall quality of the image for processing, cropping, and resizing in WordPress via ImageMagick PHP.

If ImageMagick is not installed on your server, you will see an “ImageMagick PHP module not found” warning on the plugin settings page.

Before you install ImageMagick, make sure you have the proper PHP version for your web application.

Depending on the installed PHP version, you will require a different way to install ImageMagic. But once you’re done installing Imagick for WordPress, it will be available for all web apps that use the same version of PHP on your server.

To install imagemagick for Windows, run the below-mentioned commands as your server’s root user:

 sudo apt-get -y install gcc make autoconf libc-dev pkg-config

sudo apt-get -y install libmagickwand-dev

sudo peclX.Y-sp install imagick

When the following appears:

Please provide the prefix of Imagemagick installation [autodetect]:

Press Enter. Do not type a prefix (i.e., allow autodetect).

Once installed, create a configuration file for the extension and restart PHP by running the following commands as root: 

sudo bash -c “echo extension=imagick.so > /etc/phpX.Y-sp/conf.d/imagick.ini”

sudo service phpX.Y-fpm-sp restart

Configure LSPHP Imagic:

LiteSpeed has a unique PHP compiler optimized to work with LiteSpeed products. LSPHP operates as a separate process and has a standalone binary that can be used to execute PHP programs from the command line. The LSAPI is an API that enables the communication between LiteSpeed and third-party web engines.

How to install LSPHP IMAGIC

To install LSPHP IMAGIC, you must first specify the version of PHP you prefer to use. If you don’t know the command and wish to look up a suitable package name, list the following packages.

In UBUNTU:

apt list lsphp*

in centos:

yum list lsphp*

These commands will display a list of all available packages.

After clarifying the version run, install IMAGIC in the LSPHP.

In UBUNTU:

APT install lsphpXX-imagic

In CENTOS:

APT install lsphpXX-imagic

XX will be replaced by your PHP version, such as 74 for 7.4.

Since Cloudpages is only compatible with UBUNTU, you must install it using the APT package manager.

Using Imagick with PDF Files

ImageMagick was not developed to handle untrusted PDF files. However, handling of PDF files as shown below is dangerous if malicious PDF files are processed.

Moreover, working around PDF security issues in ImageMagick through Ghostscript is also dangerous as Ghostscript is vulnerable when processing malicious PDF files.

To allow Imagick WordPress or imagemagick for Windows to process PDF files, you need to SSH into your server as root and edit this file:

/etc/ImageMagick-6/policy.xml

Locate the following line

<policy domain=”coder” rights=”none” pattern=”PDF” />

Comment out the following line by replacing it with the following:

Now, restart PHP:

sudo service phpX.Y-fpm-sp restart 

Installation Verification

You can easily verify the installation of the Imagick PHP extension with the following command:

phpX.Y-sp -i | grep imagick

If PHP ImageMagick is correctly installed, you will see the following:

/etc/phpX.Y-sp/conf.d/imagick.ini,

imagick

imagick module => enabled

imagick module version => 3.4.3RC1

imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator

Imagick compiled with ImageMagick version => ImageMagick 6.6.9-7 2016-06-01 Q16 http://www.imagemagick.org

Imagick using ImageMagick library version => ImageMagick 6.6.9-7 2016-06-01 Q16 http://www.imagemagick.org

imagick.locale_fix => 0 => 0

imagick.progress_monitor => 0 => 0

imagick.skip_version_check => 0 => 0

Applying PHP ImageMagick to WordPress

WordPress supports ImageMagic for image processing extensions to crop and resize images on a website. By default, WordPress tries to use Imagick PHP. If it isn’t available or doesn’t support the mime-type that was asked for, you can use the GD extension instead.

For more control over the quality of resized images, you can use the PHP ImageMagick Engine WordPress Plugin.

There is another plugin called Image Watermark WordPress. Using Imagick WordPress, this plugin lets you add a watermark to every image you upload to your WordPress site.

After enabling PDF support for the PHP ImageMagick extension, you will get an extra bonus. When you add a PDF file to your WordPress site, it will automatically make an image of it.

Final Words

In this blog post, we will go through how to install the imagemagick PHP extension or ImageMagick for your website. Do you currently use ImageMagick to handle images on your WordPress site? If so, share your experience with us.

Become CloudPages

Community Member to Get Latest Updates.

Pin It on Pinterest

Share This
Scroll to Top