A standalone ImageMagick for macOS


How to build portable ImageMagick for macOS:

You will need brew, but do not install imagemagick from brew, because the portable version that you are about to build will not be created if the brew version is present.

Install packages from brew, using this one-line command (possibly not all of them are needed, but it can't hurt to install them):

brew install cmake jpeg dylibbundler webp openexr little-cms2 pkg-config glib fontconfig ghostscript freetype gettext libzip libraqm libheif jbigkit pango libraw libwmf djvulibre pango librsvg

Install liblqr:Download the code from https://github.com/carlobaldassi/liblqr. Move the downloaded folder into a convenient directory and CD into it. Then (two lines):

./configure && make
sudo /usr/bin/install -c lqr/.libs/liblqr-1.0.dylib /usr/local/lib/liblqr-1.0.dylib

Install jxl: Start in any convenient directory. Then (all one line):

git clone https://github.com/libjxl/libjxl.git --recursive --shallow-submodules

On Intel and on ARM under Monterey: Edit libjxl/lib/jxl_cms.cmake and libjxl/lib/jxl.cmake by commenting out (or deleting) the line:

set(LINKER_EXCLUDE_LIBS_FLAG "-Wl,--exclude-libs=ALL")

Next, build and install libjxl (seven lines):

set(LINKER_EXCLUDE_LIBS_FLAG "-Wl,--exclude-libs=ALL")
cd libjxl
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF ..
cmake --build . -- -j$(nproc)
sudo cmake --install .

Build imagemagick: CD into your user directory or other convenient directory (two lines):

git clone https://github.com/ImageMagick/ImageMagick.git ImageMagick-7.1.1
cd ImageMagick-7.1.1

Then, on Apple Silicon (two commands, a comment, two more commands):

make distclean
./configure \
    CC=clang \
    CFLAGS="-O3" \
    CXX=clang++ \
    CXXFLAGS="-std=c++11 -O3 -march=native" \
    LDFLAGS="-L/opt/homebrew/opt/jpeg/lib" \
    CPPFLAGS="-I/opt/homebrew/opt/jpeg/include" \
    --disable-dependency-tracking \
    --without-x \
    --without-magick-plus-plus \
    --disable-shared \
    --enable-static
# check things before copying and pasting the next bit
exit
make -j 8

Or, on Intel (two commands, a comment, two more commands):

make distclean
./configure \
    CC=clang \
    CFLAGS="-O3" \
    CXX=clang++ \
    CXXFLAGS="-std=c++11 -O3 -march=native" \
    LDFLAGS="-L/usr/local/opt/jpeg/lib" \
    CPPFLAGS="-I/usr/local/opt/jpeg/include" \
    --disable-dependency-tracking \
    --without-x \
    --without-magick-plus-plus \
    --disable-shared \
    --enable-static
# check things before copying and pasting the next bit
exit
make -j 8

The executable magick will be in the utilities folder; if you run it, you'll probably get an error message.

Create a framework for the ImageMagick app: Find a simple app on your sysytem; make a copy of it; rename the copy Magick.app. Replace the the executable in Contents/MacOS with magick. Edit the info.plist file to use magick instead of the original executable. Remove any other irrelevant contents.

The app that you create will do nothing when you click on it! It exists only as a container for the executable and its required libraries!

CD into the directory with the Magick.app that you created.

Before you run the dylibbundler command below, keep in mind that you may be prompted for the location of a libjxl library; if that happens, enter: /usr/local/lib

On Apple Silicon (all one line):

dylibbundler -od -of -b -x ./Magick.app/Contents/MacOS/magick -d ./Magick.app/Contents/libs-arm/ -p @executable_path/../libs-arm/

Under Ventura or later, you may want to add the -ns parameter to avoid an error message

On Intel (all one line):

dylibbundler -od -of -b -x ./Magick.app/Contents/MacOS/magick -d ./Magick.app/Contents/libs-intel/ -p @executable_path/../libs-intel/

Now use the magick executable in the app from the command line. You can create a symlink to it in /usr/local/bin so that you can use magick without entering a path.

If you want to build a universal app, build on both Intel and Apple Silicon and use lipo to combine the magick executables. Make sure to include both the libs-arm and libs-intel folders in the universal app.


A notarized build of the standalone ImageMagick app

To save you a lot of trouble, here is a .dmg disk image with a notarized universal version of the app and an installer script that moves it into the Applications folder and creates a symlink in /usr/local/bin.


Edward Mendelson (edward [dot] mendelson [at] columbia [dot] edu)