top of page

Posts

ImageMagick and Imagick Installation



The other day, I had to install ImageMagick on Linux, it was quite difficult because it was my first time to install it.

First of all, there was not much information available. Even if I find information, either the OS was different or the version was old, or the method was completely different.

Every time I get an error about package dependencies, I get garbled texts.

This is a reminder of when it worked in the AlmaLinux 8 environment. May it be useful to someone in future.


Difference between ImageMagick and Imagick


The first thing to understand is that ImageMagick and Imagick are different. (If you know what I'm talking about, skip this section.)

ImageMagick is a free and open-source software for editing and converting image files.

Imagick is a PHP extension that allows you to create and edit image files from PHP using the ImageMagick API.

So please note that if you just install ImageMagick, you cannot run it from the PHP side!


The environment


  • AlmaLinux 8.8

  • Apache 2.4.37

  • PHP 8.1.23

  • PHP-FPM 8.1.23

Install remi repository to begin.


Install ImageMagick


If you try to install it without thinking, you will get an error like this because the required package does not exist just like the following,

dnf install --enablerepo=remi ImageMagick7 ImageMagick7-devel
Last metadata expiration check: 0:54:50 ago on Fri Sep 15 15:54:10 2023.
Error:
Problem: cannot install the best candidate for the job
  - nothing provides jasper-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides OpenEXR-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides ghostscript-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides jbigkit-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides lcms2-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides openjpeg2-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

add and activate the repository that is called "PowerTools",

dnf config-manager --set-enabled powertools

and then when I tried again, I was able to install it successfully, including dependencies!

dnf install --enablerepo=remi ImageMagick7 ImageMagick7-devel
AlmaLinux 8 - PowerTools                                                       	938 kB/s | 3.2 MB 	00:03
Last metadata expiration check: 0:00:02 ago on Sat Sep 16 16:35:59 2023.
Dependencies resolved.
===================================================================================================================
 Package                              	Arch   	Version                              	Repository  	Size
===================================================================================================================
Installing:
 ImageMagick7                         	x86_64 	1:7.1.1.15-1.el8.remi                	remi       	110 k
 ImageMagick7-devel                   	x86_64 	1:7.1.1.15-1.el8.remi                	remi       	143 k
Installing dependencies:
 ImageMagick7-libs                    	x86_64 	1:7.1.1.15-1.el8.remi                	remi       	2.5 M
 LibRaw                               	x86_64 	0.19.5-3.el8                         	appstream  	315 k
 OpenEXR-devel                        	x86_64 	2.2.0-12.el8                         	powertools  	85 k
 OpenEXR-libs                         	x86_64 	2.2.0-12.el8                         	appstream  	671 k
 adobe-mappings-cmap                  	noarch 	20171205-3.el8                       	appstream  	2.1 M
 adobe-mappings-cmap-deprecated       	noarch 	20171205-3.el8                       	appstream  	118 k
 adobe-mappings-pdf                   	noarch 	20180407-1.el8                       	appstream  	706 k
 atk                                  	x86_64 	2.28.1-1.el8                         	appstream  	271 k
 avahi-libs                           	x86_64 	0.7-20.el8                           	baseos      	61 k
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Installing weak dependencies:
 ImageMagick7-djvu                    	x86_64 	1:7.1.1.15-1.el8.remi                	remi        	66 k
 open-sans-fonts                      	noarch 	1.10-6.el8                           	appstream  	482 k
Enabling module streams:
 nginx                                           	1.14
 php                                             	7.2
Transaction Summary
===================================================================================================================
Install  142 Packages
Total download size: 51 M
Installed size: 155 M

If the version is displayed, installation is complete.

magick --version

Version: ImageMagick 7.1.1-15 Q16-HDRI x86_64 21298 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zip zlib
Compiler: gcc (8.5)
Install Imagick

Install Imagick



Same as ImageMagick, you will get an error if you try to install it because the required package does not exist. So, let’s install the required packages first.

dnf install --enablerepo=remi php-pear php-devel

Check if you can run the pecl command.

which pecl
/usr/bin/pecl

Install it with pecl.

Press Enter after you see "Please provide the prefix of ImageMagick installation" on the screen to proceed with the installation.

pecl install imagick
 
downloading imagick-3.7.0.tgz ...
Starting to download imagick-3.7.0.tgz (360,138 bytes)
.........................................................................done: 360,138 bytes
33 source files, building
running: phpize
Configuring for:
PHP Api Version:     	20170718
Zend Module Api No:  	20170718
Zend Extension Api No:   320170718

Please provide the prefix of ImageMagick installation [autodetect] :

The message upon when the installation completed instructs "You should add "extension=imagick.so" to php.ini", so add the following to the bottom of php.ini.

# ↓add this following in the php.ini 
 
[PECL]
extension=imagick.so

and then restart Apache and PHP-FPM.

systemctl restart httpd
systemctl restart php-fpm.service

Install additional PHP packages after the restart and if they appear in the PHP module, ok.

dnf install php81-php-pecl-imagick-im7

php -m | grep imagick
imagick

Now you can check the current policy with the following command.

magick -list policy

Path: /etc/ImageMagick-7/policy.xml
  Policy: Undefined
    rights: None
  Policy: Delegate
    rights: None
   pattern: *
  Policy: Filter
    rights: None
    pattern: *
  Policy: Coder
    rights: None
    pattern: *
  Policy: Coder
    rights: Read Write
    pattern: {PNG,JPEG,JPG,GIF,WEBP}
 
Path: [built-in]
  Policy: Undefined
    rights: None

This blog post is translated from a blog post written by Kawa Ken on our Japanese website Beyond Co..


Recent Posts

See All

Comments


bottom of page