How to Install PHP 7 Imagick Extension on Ubuntu 16.04

Imagick ubuntu16 install

The php imagick extension enables servers to create, edit, convert and/or manipulate images via PHP using the ImageMagick software. It can read and write images in most of the image formats including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PNG, Postscript, SVG, and TIFF. 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. You can use ImageMagick without Imagick but you need both Imagick and ImageMagick installed in the server to run it within the PHP code. This article covers the installation of PHP Imagick extension on Ubuntu 16.04.

Suggested Read: How to Install Imagemagick 7 on Debian

Install ImageMagick

At first, You need to install ImageMagic. To accomplish it, execute the following command from the terminal.

# sudo apt-get install imagemagick

Install php imagick extension

To use add-apt-repository, install the package python-software-properties

# sudo apt-get install  python-software-properties software-properties-common

Now add ppa:ondrej/php repository to apt database and update the system.

# sudo add-apt-repository -y ppa:ondrej/php
# sudo apt-get update

Install php 7.1

# sudo apt-get install php7.1

If you have not installed apache or apache module for php 7.1 earlier then install it using following command from the terminal.

# sudo apt-get install apache2 libapache2-mod-php7.1

Install php imagick extension using the following command from the terminal and restart apache.

# sudo apt-get install php-imagick
# sudo systemctl restart apache2

Verify the installation

Using the following command, check if the imagick extension is loaded by apache.

# php -m | grep imagick

You can also verify the same using phpinfo(). Assuming the root of your web server is /var/www/html. Navigate to the folder and create the phpinfo file.

# cd /var/www/html
# vi info.php
<? php
     echo phpinfo();

Now if you point your browser to http://Your-Server-IP/info.php you can find all loaded modules including php-imagick.

php imagick extension

The Imagick extension add to PHP the power of ImageMagick image manipulation tool. One of its advantage is that it can read a lot more image formats than GD. The image formats supported by ImageMagick can be seen in the above output and the no of formats are over 100.

3 Comments... add one

  1. it's good tutorial but for god sack can your turn off this stupid autoplay video ads ! I have limited internet subscription and don't open videos that much , that's freaking annoying man .


Leave a Comment