Building ImageMagick from Source with HEIF, WebP, and Modern Codecs on macOS

By Ercan - 27/10/2025

If you’ve ever tried to compile ImageMagick with full codec support (HEIF, WebP, PNG, JPEG, TIFF, etc.) on macOS, you know it’s not a trivial task.
Precompiled binaries often lack optional delegates like HEIF or WebP due to licensing and dependency complexity.
In this post, we’ll walk through the process of building ImageMagick entirely from source, including all the required libraries and codecs.


1. Why Build from Source?

Building from source gives you:

  • ✅ Full control over which codecs and features are included.
  • ⚙️ Compatibility with your system architecture (Apple Silicon or Intel).
  • 🔒 Isolation — all dependencies installed in a custom directory, keeping your system clean.
  • 📦 The ability to enable formats often missing from prebuilt binaries (e.g., HEIF or AVIF).

2. Preparation

Before you start, make sure cmake and pkg-config are installed:

brew install cmake pkg-config

Then create two directories — one for source codes and another for compiled libraries:

mkdir -p $HOME/Applications/imagemagick_sources
mkdir -p $HOME/Applications/imagemagick_library

3. Building Dependencies Step by Step

The following libraries will be built in order:

Library Purpose
nasm SIMD CPU Optimization
libpng PNG format
libjpeg-turbo JPEG and JPEG8 compatibility
libtiff TIFF image format
freetype Font rendering
djvulibre DjVu format
libwebp WebP image format
SDL2 Needed for libde265
libde265 HEVC decoder for HEIF
x265 HEVC encoder for HEIF
libaom AV1 codec support for HEIF
libheif Main HEIF/AVIF image library
ImageMagick Final build with all delegates

 

Each dependency is built using the similar pattern:

cmake -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install

This ensures everything installs under your isolated path ($HOME/Applications/imagemagick_library).


4. Building ImageMagick

Once all libraries are installed, it’s time to build ImageMagick itself:

cd $HOME/Applications/imagemagick_sources
curl -L https://github.com/ImageMagick/ImageMagick/archive/refs/tags/7.1.2-8.tar.gz -o 7.1.2-8.tar.gz
tar -zxvf 7.1.2-8.tar.gz
cd ImageMagick-7.1.2-8

CPPFLAGS="-I$HOME/Applications/imagemagick_library/include" \
LDFLAGS="-L$HOME/Applications/imagemagick_library/lib" \
PKG_CONFIG_PATH="$HOME/Applications/imagemagick_library/lib/pkgconfig" \
./configure --prefix="$HOME/Applications/ImageMagick-NoTRD-V7.1.2-8" \
            --without-threads \
            --disable-shared \
            --enable-delegate-build
make && make install

After installation, update the runtime path so the magick binary can find your custom-built libraries:

install_name_tool -add_rpath $HOME/Applications/imagemagick_library/lib \
$HOME/Applications/ImageMagick-NoTRD-V7.1.2-8/bin/magick

You can verify the build by running:

magick identify -list format

5. Result

You now have a fully self-contained ImageMagick installation with complete format support, including HEIF, WebP, PNG, JPEG, and more — all built natively for your system architecture.

For convenience, you can export the magick binary to your PATH:

export PATH="$HOME/Applications/ImageMagick-NoTRD-V7.1.2-8/bin:$PATH"

The full build script is available as a Gist:
👉 View on GitHub Gist

Tags: imagemagick