How to Install PHP 7 Imagick Extension on Ubuntu 16.04

Imagick ubuntu16 installThe 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 installation of PHP Imagick extension on Ubuntu 16.04.

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

About Dwijadas Dey

Dwijadas Dey is working with GNU/Linux, Open source systems since 2005. Having avid follower of GNU/Linux, He believes in sharing and spreading the open source ideas to the targeted audience. Apart from freelancing he also writes for community. His current interest includes information and network security.

Author Archive Page

Have anything to say?

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

All comments are subject to moderation.