# ============================================================
# ImageMagick Build Script (macOS / source-based installation)
# ============================================================
# This script builds ImageMagick from source with support for
# HEIF, WebP, PNG, JPEG, TIFF, FreeType, and more.
# All libraries are installed into a custom isolated directory.
# ============================================================
brew install cmake pkg-config
mkdir -p $HOME/Applications/imagemagick_sources
mkdir -p $HOME/Applications/imagemagick_library
# === nasm === #
# SIMD CPU Optimization
cd $HOME/Applications/imagemagick_sources
curl https://www.nasm.us/pub/nasm/releasebuilds/3.01/nasm-3.01.tar.gz -o nasm.tar.gz
mkdir -p nasm && tar -zxvf nasm.tar.gz -C ./nasm --strip-components=1 && rm nasm.tar.gz
cd nasm
./configure --prefix="$HOME/Applications/imagemagick_library"
make && make install
export PATH="$HOME/Applications/imagemagick_library/bin:$PATH"
# === libpng === #
cd $HOME/Applications/imagemagick_sources
git clone --branch 'v1.6.50' --depth 1 --single-branch https://github.com/pnggroup/libpng.git
cd libpng
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install
# === libjpeg-turbo === #
cd $HOME/Applications/imagemagick_sources
git clone --branch '3.1.2' --depth 1 --single-branch https://github.com/libjpeg-turbo/libjpeg-turbo.git
cd libjpeg-turbo
mkdir build && cd build
cmake -DWITH_JPEG8=ON -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install
# === libwebp === #
cd $HOME/Applications/imagemagick_sources
git clone --branch 'v1.6.0' --depth 1 --single-branch https://chromium.googlesource.com/webm/libwebp
cd libwebp
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install
# === libtiff === #
cd $HOME/Applications/imagemagick_sources
git clone --branch 'v4.7.1' --depth 1 --single-branch https://gitlab.com/libtiff/libtiff.git
cd libtiff/build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -Dwebp=OFF -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install
# === freetype === #
cd $HOME/Applications/imagemagick_sources
git clone --branch 'VER-2-14-1' --depth 1 --single-branch https://gitlab.freedesktop.org/freetype/freetype.git
cd freetype
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install
# === djvulibre === #
cd $HOME/Applications/imagemagick_sources
curl -L http://downloads.sourceforge.net/djvu/djvulibre-3.5.29.tar.gz -o djvulibre.tar.gz
mkdir -p djvulibre && tar -zxvf djvulibre.tar.gz -C ./djvulibre --strip-components=1 && rm djvulibre.tar.gz
cd djvulibre
CPPFLAGS="-I$HOME/Applications/imagemagick_library/include" LDFLAGS="-L$HOME/Applications/imagemagick_library/lib" ./configure --prefix="$HOME/Applications/imagemagick_library"
make && make install
# === libSDL2 === #
# Required when building libde265
cd $HOME/Applications/imagemagick_sources
git clone --branch 'release-2.32.10' --depth 1 --single-branch https://github.com/libsdl-org/SDL.git
cd SDL
mkdir build && cd build
CPPFLAGS="-I$HOME/Applications/imagemagick_library/include" LDFLAGS="-L$HOME/Applications/imagemagick_library/lib" ../configure --prefix="$HOME/Applications/imagemagick_library"
make && make install
# === libde265 === #
# HEVC decoder for HEIF
cd $HOME/Applications/imagemagick_sources
git clone --branch 'v1.0.16' --depth 1 --single-branch https://github.com/strukturag/libde265.git
cd libde265
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install
# === x265 === #
# HEVC encoder for HEIF
cd $HOME/Applications/imagemagick_sources
git clone --branch 'master' --depth 1 --single-branch https://bitbucket.org/multicoreware/x265_git.git x265
cd x265/build/xcode
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" ../../source
make && make install
# === libaom === #
# AV1 codec support for HEIF
# Adjust AOM_TARGET_CPU according to your architecture (x86_64 for Intel, arm64 for Silicon).
cd $HOME/Applications/imagemagick_sources
git clone --branch 'v3.13.1' --depth 1 --single-branch https://aomedia.googlesource.com/aom
cd aom/build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" ../ -DCMAKE_BUILD_TYPE=Release -DAOM_TARGET_CPU=x86_64
make && make install
# === libheif === #
cd $HOME/Applications/imagemagick_sources
git clone --branch 'v1.20.2' --depth 1 --single-branch https://github.com/strukturag/libheif.git
cd libheif
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/imagemagick_library" \
-DLIBSHARPYUV_INCLUDE_DIR="$HOME/Applications/imagemagick_library/include/webp" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$HOME/Applications/imagemagick_library" \
-DWITH_EXAMPLES=OFF ../
make && make install
# === ImageMagick === #
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
# Add library path to the executable
install_name_tool -add_rpath $HOME/Applications/imagemagick_library/lib \
$HOME/Applications/ImageMagick-NoTRD-V7.1.2-8/bin/magick
Last active
November 16, 2025 10:47
-
-
Save ercansormaz/b555c9e986f1c489a14ea41fcadddf20 to your computer and use it in GitHub Desktop.
Building ImageMagick from Source with HEIF, WebP, and Modern Codecs on macOS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment