Enable HEIC support for ImageMagick on Centos8

Steps to recompile ImageMagick with HEIC support on Centos8 / AlmaLinux 8.

Note: adjust paths according to your environment

Step 1 – enable extra EPEL and RPM Fusion repository

dnf install epel-release
dnf config-manager --set-enabled powertools
dnf install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
dnf install libde265-devel x265-devel libaom-devel libheif libheif-devel openjpeg2-devel ffmpeg-devel libtool-ltdl libtool-ltdl-devel pango pango-devel ghostscript

Step 2 – compile latest ImageMagick

cd /root/install
git clone https://github.com/ImageMagick/ImageMagick.git
cd ImageMagick
./configure --prefix=/usr --with-modules --with-heic=yes
# make sure, that in the output of configure command you see, that HEIC support is enabled
make -j 2
make install

Step 3 – compile imagick PECL module for PHP

# adjust accordingly to your PHP path and PHP version
cd /root/install
wget https://pecl.php.net/get/imagick-3.8.1.tgz
tar -zxf imagick-3.8.1.tgz
cd imagick-3.8.1
make clean
/opt/php-8.4/bin/phpize
'./configure' '--with-php-config=/opt/php-8.4/bin/php-config'
make
make install

Step 4 – test

php -r ‘$i=new Imagick(); print_r($i->queryFormats());’ | grep -i heic
# if all is good – you should see HEIC in the output.