
Install ImageMagick on a server (with HEIC support)
ImageMagick is a pretty neat image convert tool, with support for animated gif. It is well integrated to the Drupal ecosystem. Here is how to install it on modern systems.
1. Install the dependencies
Make sure that you have [https://github.com/ImageMagick/ImageMagick/discussions/6682#discussioncomment-9066741](libtool and gcc installed). To do so, use the following command:
On AlmaLinux :
sudo yum install libtool gcc-c++ gcc make git wget libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel freetype-devel ghostscript libX11-devel libxml2-devel libwmf-devel zlib-devel
On Ubuntu :
sudo apt install libtool gcc-c++ gcc make git wget libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel freetype-devel ghostscript libX11-devel libxml2-devel libwmf-devel zlib-devel
2. Download and extract the selected ImageMagick package
Choose the tar.gz
version you want from the following list and copy the URL
Download the package from ImageMagick website and extract it to the ImageMagick-7
folder with the following commands:
cd /usr/src/
mkdir imagemagick
cd imagemagick
wget https://download.imagemagick.org/archive/releases/ImageMagick-7.1.2-3.tar.gz
tar -xvzf ImageMagick-7.1.2-3.tar.gz
mv ImageMagick-7.1.2-3 ImageMagick-7
cd ImageMagick-7
3. Install ImageMagick
Build and install ImageMagick with the following commands:
./configure
make
sudo make install
make check
sudo ldconfig
4. Validate the installation
Run the following command to make sure that ImageMagick is now available:
which convert
The list of supported file types can be validated with the following command:
magick -list format
Or check the support for a specific file type with the following command:
magick -list format | grep AVIF
5. (optional) HEIC support
Le passage suivant décrit les étapes facultatives pour ajouter le support des fichiers HEIC sur AlmaLinux 8.9. Les commandes sont différentes sur Ubuntu et certains dépendances ne sont peut-être pas requises sur AlmaLinux > 8.9
Supporting additional file types brings its own set of complications. Additional libraries must be installed and compiled. During ImageMagick installation, these will be loaded if enabled (e.g., --with-heic=yes
).
If you want to support .heic
and .avif
files, the libde265
and libheif
libraries are required. Compiling them requires cmake
and a recent version of GCC (g++), which is not included with AlmaLinux 8.9.
Build Dependencies
On AlmaLinux 8.9, run the following commands to install build dependencies:
yum update
sudo dnf install gcc-toolset-14
sudo dnf install cmake
It's important to note that installing GCC does not replace the operating system's gcc
, which is good news from a stability perspective. However, it does mean that we need to specify which gcc to use when we compile.
Compiling the libde265 and libheif libraries
Using the CC
, CCX
, CMAKE_C_COMPILER
, and CMAKE_CXX_COMPILER
parameters, it is possible to specify the version of the C++ compiler to use.
# Additional dependency
yum install x265 x265-devel
# libde265
cd /usr/src/
sudo git clone https://github.com/strukturag/libde265.git --branch v1.0.16
cd libde265/
sudo ./autogen.sh
sudo ./configure
sudo make CC=/opt/rh/gcc-toolset-14/root/usr/bin/gcc CXX=/opt/rh/gcc-toolset-14/root/usr/bin/g++
sudo make install CC=/opt/rh/gcc-toolset-14/root/usr/bin/gcc CXX=/opt/rh/gcc-toolset-14/root/usr/bin/g++
# libheif
cd /usr/src/
sudo git clone https://github.com/strukturag/libheif.git --branch v1.20.2
cd libheif/
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr -D CMAKE_C_COMPILER=/opt/rh/gcc-toolset-14/root/usr/bin/gcc -D CMAKE_CXX_COMPILER=/opt/rh/gcc-toolset-14/root/usr/bin/g++ --preset=release ..
sudo make CC=/opt/rh/gcc-toolset-14/root/usr/bin/gcc CXX=/opt/rh/gcc-toolset-14/root/usr/bin/g++
sudo make install CC=/opt/rh/gcc-toolset-14/root/usr/bin/gcc CXX=/opt/rh/gcc-toolset-14/root/usr/bin/g++
sudo ldconfig /usr/lib64/
CMAKE_INSTALL_PREFIX: specifying CMAKE_INSTALL_PREFIX=/usr
ensures that the library is installed in /usr/lib64
rather than /usr/local/lib64
. This makes it easier to discover the library, as this folder is in the default pkg-config
configuration, which is used by ImageMagick. You can see which folders are searched by using the pkg-config --variable pc_path pkg-config
command.
Then, we recompile ImageMagick with the additional libraries:
cd /usr/src/imagemagick/ImageMagick-7
./configure --with-heic=yes --with-jpeg=yes --with-png=yes --with-tiff=yes --with-webp=yes
make
sudo make install
The instructions are based on the article Medium - How to Install ImageMagick with HEIC Support on CentOS Linux (and Other Linux Distributions).