How to Install ImageMagick with HEIC Support on CentOS Linux (and Other Linux Distributions)

Harshit Bhardwaj
6 min readJun 17, 2023

--

Introduction:

ImageMagick is a powerful open-source software suite designed for image manipulation, conversion, and processing. However, handling the High-Efficiency Image Format (HEIC) has posed challenges for many image editing tools. If you’re a user of CentOS Linux or any other Linux distribution, you can follow a specific installation process to enable ImageMagick with HEIC support. This guide provides clear instructions to install ImageMagick with HEIC support on your Linux system.

HEIC files have gained popularity for their exceptional image quality and reduced file sizes, primarily used in Apple’s iOS devices. However, efficiently working with HEIC files can be hindered by compatibility issues. By installing ImageMagick with HEIC support on CentOS or other Linux distributions, you can unlock seamless editing, conversion, and processing capabilities for HEIC files.

While this guide primarily focuses on CentOS Linux, the installation steps can be easily adapted for other Linux distributions with slight adjustments. By following the concise instructions provided, you’ll equip your Linux system with the powerful functionality of ImageMagick and explore a multitude of possibilities for image manipulation and conversion.

If you’re eager to leverage the capabilities of ImageMagick to work with HEIC files on your CentOS or Linux-based systems, let’s dive into the step-by-step instructions and unlock a world of opportunities for image processing and conversion.

Section 1: Installing Dependencies

To enable HEIC support in ImageMagick, we need to install the libpng dependency. Libpng is essential for modifying PNG images and compiling libheif and libde265. It provides the necessary functionality to handle PNG files effectively.

Please follow these step-by-step instructions to install libpng:

# Navigate to the /usr/src/ directory
cd /usr/src/

# Download the libpng source code
wget https://sourceforge.net/projects/libpng/files/libpng16/1.6.37/libpng-1.6.37.tar.gz --no-check-certificate

# Extract the downloaded tarball
tar -zxvf libpng-1.6.37.tar.gz

# Change into the libpng source code directory
cd libpng-1.6.37/

# Configure the build
sudo ./configure --prefix=/usr/local/libpng

# Compile the source code
sudo make

# Install libpng
sudo make install

Please note that libpng version 1.6.32 or later is required for this installation. You can refer to the following link for more information: https://github.com/strukturag/libheif/issues/77

Once the installation process is complete, libpng will be successfully installed on your system, providing the necessary support for image modification and compilation of libheif and libde265.

Section 2: Setting the PKG_CONFIG_PATH

The PKG_CONFIG_PATH environment variable is crucial for locating the necessary libraries and their associated files during the build process. It provides the build system with information about the installed libraries and their dependencies, allowing it to find and link against them correctly.

To set the PKG_CONFIG_PATH and include the necessary paths for libde265 and libheif, follow this step:

# Set the PKG_CONFIG_PATH environment variable to include the necessary paths for libde265 and libheif
export PKG_CONFIG_PATH=/usr/src:/usr/src/libheif:/usr/src/libde265:/usr/src/libpng-1.6.37

# Alternatively, you can use the following command to locate .pc files and set the PKG_CONFIG_PATH:
# Run 'locate --basename '.pc'' to find .pc files in your system
# Note: Before using the 'locate' command, make sure to run 'sudo updatedb' to ensure an up-to-date database of files.

By setting the PKG_CONFIG_PATH and including the necessary paths, you ensure that the build process can locate the required libraries and their associated files. This is essential for the successful compilation and installation of ImageMagick with HEIC support.

Section 3: Building and Installing libde265 and libheif

libde265 and libheif are essential libraries that enable support for the High-Efficiency Image Format (HEIF), including the HEIC image format. libde265 is responsible for decoding HEVC (High-Efficiency Video Coding) images, while libheif provides a high-level API for reading and writing HEIF files.

To build and install libde265, it is important to note that using a version other than 1.0.10 is recommended. The issue with the broken pc file of libde265 1.0.10 can cause the error “@CMAKE_INSTALL_PREFIX@/lib: No such file or directory”.

To build and install libde265 and libheif, follow these instructions:

# Navigate to the /usr/src/ directory
cd /usr/src/

# Clone the libde265 repository from GitHub
sudo git clone https://github.com/strukturag/libde265.git

# Change into the libde265 directory
cd libde265/

# Run the autogen.sh script
sudo ./autogen.sh

# Configure the build
sudo ./configure

# Compile the source code
sudo make

# Install libde265
sudo make install

# Return to the /usr/src/ directory
cd /usr/src/

# Clone the libheif repository from GitHub
sudo git clone https://github.com/strukturag/libheif.git

# Change into the libheif directory
cd libheif/

# Run the autogen.sh script
sudo ./autogen.sh

# Configure the build
sudo ./configure

# Compile the source code
sudo make

# Install libheif
sudo make install

By following these instructions, you will be able to build and install libde265 and libheif. These libraries are crucial for enabling HEIC support in ImageMagick, allowing you to work with HEIC images effectively.

Section 4: Building and Installing ImageMagick

To build and install ImageMagick with the desired options, follow these steps:

# Navigate to the /usr/src/ directory
cd /usr/src/

# Download the ImageMagick source code
sudo wget https://www.imagemagick.org/download/ImageMagick.tar.gz --no-check-certificate

# Extract the downloaded tarball
sudo tar -zxvf ImageMagick.tar.gz

# Change into the ImageMagick source code directory
cd ImageMagick-7*
# Replace version with the specific version number you have downloaded

# Configure the build with desired options
sudo ./configure --prefix=/usr/local/ImageMagick-7.1.0-60 \
--with-heic=yes \
--with-jpeg=yes \
--with-png=yes \
--with-tiff=yes \
--with-webp=yes

# Compile the source code
sudo make

# Install ImageMagick
sudo make install

# Run ldconfig to update library cache
# The ldconfig command is used to update the system's library cache,
# ensuring that the newly installed ImageMagick library is recognized.
sudo ldconfig

By following these instructions, you will be able to download the ImageMagick source code, configure it with the desired options (such as enabling HEIC support), compile the source code, and install ImageMagick.

Section 5: Verification and Troubleshooting

After installing ImageMagick with HEIC support, you can verify its installation and check for the availability of HEIC decoders and encoders. Here’s how you can do it:

# Verify the installation of ImageMagick by using the convert command
/usr/local/ImageMagick-7.1.0-60/bin/convert -version

# The above command will display the ImageMagick version and other relevant information if it is installed correctly.

# To check the available HEIC decoders, use the heif-convert command
heif-convert --list-decoders

# Running the heif-convert command will list the decoders supported by ImageMagick for HEIC files. This will show the available options for decoding HEIC images.

# Similarly, to list the available HEIC encoders, use the heif-enc command
heif-enc --list-encoders

# The heif-enc command will provide a list of encoders supported by ImageMagick for HEIC files. This will show the available options for encoding HEIC images.

Checking config.log file:

In case any issues or errors arise during the installation process, it is crucial to examine the config.log file for each library to identify the problem. The config.log file contains detailed information about the configuration and compilation process. To check the config.log file for a particular library, navigate to the library’s installation directory and open the config.log file using a text editor.

For example, to check the config.log file for libpng, use the following command:

cd /usr/src/libpng/
sudo vi config.log

Similarly, for libde265 and libheif, navigate to their respective installation directories and open the config.log files.

Carefully examine the content of the config.log files, paying attention to any error messages, missing dependencies, or configuration issues. The information in these log files can provide valuable insights into the cause of any installation problems.

By performing verification checks and reviewing the config.log files for all three libraries (libpng, libde265, and libheif), you can ensure the successful installation of the required dependencies and troubleshoot any potential issues effectively.

Conclusion:

Enabling HEIC support in ImageMagick expands your possibilities for working with HEIC image files. By following the provided instructions, you can install the necessary dependencies, build ImageMagick with HEIC support, and explore its powerful features. Enjoy the benefits of efficient manipulation, conversion, and processing of HEIC images using ImageMagick.

Take this opportunity to unleash your creativity and experiment with ImageMagick’s HEIC support. Explore the endless possibilities it offers for image manipulation, conversion, and processing. With ImageMagick and HEIC support, you can elevate your projects and bring your vision to life. Happy exploring!

Additional References:

For further information and detailed documentation on libheif and libde265, you can refer to the following resources:

  1. libheif GitHub README
  2. libde265 GitHub README

--

--