Skip to content

Instantly share code, notes, and snippets.

@hurricup
Last active April 10, 2024 01:17
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save hurricup/e14ae5bc47705fca6b1680e7a1fb6580 to your computer and use it in GitHub Desktop.
Save hurricup/e14ae5bc47705fca6b1680e7a1fb6580 to your computer and use it in GitHub Desktop.
How to install ImageMagick 7.1.0-54 with HEIC and WEBP support on Ubuntu 20.04
# inspired by https://gist.github.com/rjnienaber/af47fccb8410926ba7ea35f96c3b87fd
# remove bundled ImageMagick
sudo apt remove imagemagick -y
# install base dependencies
sudo apt-get install -y \
build-essential \
git \
libde265-dev \
libdjvulibre-dev \
libfftw3-dev \
libghc-bzlib-dev \
libgoogle-perftools-dev \
libgraphviz-dev \
libgs-dev \
libheif-dev \
libjbig-dev \
libjemalloc-dev \
libjpeg-dev \
liblcms2-dev \
liblqr-1-0-dev \
liblzma-dev \
libopenexr-dev \
libopenjp2-7-dev \
libpango1.0-dev \
libraqm-dev \
libraw-dev \
librsvg2-dev \
libtiff-dev \
libwebp-dev \
libwmf-dev \
libxml2-dev \
libzip-dev \
libzstd-dev
# installing
git clone --depth 1 --branch 7.1.0-54 https://github.com/ImageMagick/ImageMagick.git
cd ImageMagick
# options omitted from the configure
# --with-autotrace=yes \ # requires autotrace from the github, looks abandoned
# --with-dps=yes \ # ?
# --with-flif=yes \ # ?
# --with-fpx=yes \ # ?
# --with-jxl=yes \ # requires libjxl from the github
# --with-ltdl=no \ # ?
./configure \
--with-bzlib=yes \
--with-djvu=yes \
--with-dps=yes \
--with-fftw=yes \
--with-flif=yes \
--with-fontconfig=yes \
--with-fpx=yes \
--with-freetype=yes \
--with-gslib=yes \
--with-gvc=yes \
--with-heic=yes \
--with-jbig=yes \
--with-jemalloc=yes \
--with-jpeg=yes \
--with-jxl=yes \
--with-lcms=yes \
--with-lqr=yes \
--with-lzma=yes \
--with-magick-plus-plus=yes \
--with-openexr=yes \
--with-openjp2=yes \
--with-pango=yes \
--with-perl=yes \
--with-png=yes \
--with-raqm=yes \
--with-raw=yes \
--with-rsvg=yes \
--with-tcmalloc=yes \
--with-tiff=yes \
--with-webp=yes \
--with-wmf=yes \
--with-x=yes \
--with-xml=yes \
--with-zip=yes \
--with-zlib=yes \
--with-zstd=yes \
--with-gcc-arch=native
# ==============================================================================
# ImageMagick 7.1.0-54 is configured as follows. Please verify that this
# configuration matches your expectations.
#
# Host system type: x86_64-pc-linux-gnu
# Build system type: x86_64-pc-linux-gnu
#
# Option Value
# ------------------------------------------------------------------------------
# Shared libraries --enable-shared=yes yes
# Static libraries --enable-static=yes yes
# Build utilities --with-utilities=yes yes
# Module support --with-modules=no no
# GNU ld --with-gnu-ld=yes yes
# Quantum depth --with-quantum-depth=16 16
# High Dynamic Range Imagery
# --enable-hdri=yes yes
#
# Install documentation: yes
#
# Memory allocation library:
# JEMalloc --with-jemalloc=yes yes
# TCMalloc --with-tcmalloc=yes yes
# UMem --with-umem=no no
#
# Delegate library configuration:
# BZLIB --with-bzlib=yes yes
# Autotrace --with-autotrace=no no
# DJVU --with-djvu=yes yes
# DPS --with-dps=yes no
# FFTW --with-fftw=yes yes
# FLIF --with-flif=yes no
# FlashPIX --with-fpx=yes no
# FontConfig --with-fontconfig=yes yes
# FreeType --with-freetype=yes yes
# Ghostscript lib --with-gslib=yes yes
# Graphviz --with-gvc=yes yes
# HEIC --with-heic=yes yes
# JBIG --with-jbig=yes yes
# JPEG v1 --with-jpeg=yes yes
# JPEG XL --with-jxl=yes no
# LCMS --with-lcms=yes yes
# LQR --with-lqr=yes yes
# LTDL --with-ltdl=no no
# LZMA --with-lzma=yes yes
# Magick++ --with-magick-plus-plus=yes yes
# OpenEXR --with-openexr=yes yes
# OpenJP2 --with-openjp2=yes yes
# PANGO --with-pango=yes yes
# PERL --with-perl=yes /usr/bin/perl
# PNG --with-png=yes yes
# RAQM --with-raqm=yes yes
# RAW --with-raw=yes yes
# RSVG --with-rsvg=yes yes
# TIFF --with-tiff=yes yes
# WEBP --with-webp=yes yes
# WMF --with-wmf=yes yes
# X11 --with-x=yes yes
# XML --with-xml=yes yes
# ZIP --with-zip=yes yes
# ZLIB --with-zlib=yes yes
# ZSTD --with-zstd=yes yes
#
# Delegate program configuration:
# GhostPCL None pcl6 (unknown)
# GhostXPS None gxps (unknown)
# Ghostscript None gs (9.50)
#
# Font configuration:
# Apple fonts --with-apple-font-dir=default
# Dejavu fonts --with-dejavu-font-dir=default none
# Ghostscript fonts --with-gs-font-dir=default /usr/share/ghostscript/fonts/
# URW-base35 fonts --with-urw-base35-font-dir=default none
# Windows fonts --with-windows-font-dir=default none
#
# X11 configuration:
# X_CFLAGS =
# X_PRE_LIBS = -lSM -lICE
# X_LIBS =
# X_EXTRA_LIBS =
#
# Options used to compile and link:
# PREFIX = /usr/local
# EXEC-PREFIX = /usr/local
# VERSION = 7.1.0-54
# CC = gcc
# CFLAGS = -I/usr/include/libxml2 -I/usr/include/x86_64-linux-gnu -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -pthread -I/usr/include/librsvg-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libraw -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/OpenEXR -I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/openjpeg-2.3 -I/usr/include/graphviz -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/fribidi -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -pthread -fopenmp -Wall -g -O2 -mtune=native -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
# CPPFLAGS = -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16
# PCFLAGS =
# DEFS = -DHAVE_CONFIG_H
# LDFLAGS =
# LIBS = -ljbig -llcms2 -ltiff -lfreetype -lraqm -lfreetype -ljpeg -lgs -llqr-1 -lglib-2.0 -lpng16 -lz -ldjvulibre -lfftw3 -lfontconfig -lfreetype -lheif -lwebpmux -lwebpdemux -lwebp -lwebp -lwmflite -lXext -lXt -lSM -lICE -lX11 -llzma -lbz2 -lIlmImf -lImath -lHalf -lIex -lIexMath -lIlmThread -lpthread -lopenjp2 -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lharfbuzz -lcairo -lraw_r -lstdc++ -fopenmp -llcms2 -lrsvg-2 -lm -lgio-2.0 -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lcairo -lxml2 -lgvc -lcgraph -lcdt -lz -L/usr//usr/lib/x86_64-linux-gnu -lzip -lm -ljemalloc -lpthread -ltcmalloc_minimal
# CXX = g++
# CXXFLAGS = -pthread
# FEATURES = DPC HDRI Cipher OpenMP
# DELEGATES = bzlib djvu fftw fontconfig freetype gslib heic jbig jng jpeg lcms lqr lzma openexr openjp2 pango png ps raqm raw rsvg tiff video webp wmf x xml zip zlib zstd
# ==============================================================================
#
make -j 8
sudo make install
sudo ldconfig /usr/local/lib
# check
identify --version
# Version: ImageMagick 7.1.0-54 Q16-HDRI x86_64 ee2f46b29:20221210 https://imagemagick.org
# Copyright: (C) 1999 ImageMagick Studio LLC
# License: https://imagemagick.org/script/license.php
# Features: Cipher DPC HDRI OpenMP(4.5) TCMalloc
# Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc heic jbig jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zip zlib
# Compiler: gcc (9.4)
@dietmar
Copy link

dietmar commented Nov 30, 2021

Thanks!
build-essential is also required of course; I suggest to add that to the apt-get call.

@hurricup
Copy link
Author

@dietmar thank you. I have missed a lot of basic things probably. It's my dev machine and a lot of tools already installed in there. Worth trying to run in some clean docker container.

@iskrisis
Copy link

@hurricup thanks for this!

@SorinGFS
Copy link

First of all thanks for the job. I had to go deeper and I found the original documentation where I saw that about half of your configured modules are in fact already present by default. Here is a list of what is default extracted from the docs:

w/o Configure Option Arg Default
--enable- shared   FALSE
--disable- static   TRUE
--disable- installed   TRUE
--enable- ccmalloc   FALSE
--enable- prof   FALSE
--enable- gprof   FALSE
--enable- gcov   FALSE
--disable- openmp   TRUE
--disable- largefile   TRUE
--with- quantum-depth   FALSE
--enable- hdri   FALSE
--enable- osx-universal-binary   FALSE
--without- modules   TRUE
--with- cache   FALSE
--without- threads   TRUE
--with- frozenpaths   FALSE
--without- magick-plus-plus   TRUE
--without- perl   TRUE
--with- perl path FALSE
--with- perl-options parameters FALSE
--without- bzlib   TRUE
--without- dps   TRUE
--with- fpx   FALSE
--without- freetype   TRUE
--with- gslib   FALSE
--without- jbig   TRUE
--without- jpeg   TRUE
--without- jp2   TRUE
--without- lcms   TRUE
--without- lzma   TRUE
--without- png   TRUE
--without- tiff   TRUE
--without- wmf   TRUE
--with- fontpath path FALSE
--with- gs-font-dir path FALSE
--with- windows-font-dir path FALSE
--without- xml   TRUE
--without- zlib   TRUE
--without- x   TRUE
--with- share-path path FALSE
--with- libstdc path FALSE

So, about half of modules can be cutted off, and 6 dependencies too. Also, there is no need to specify --with-some-module=yes, --with-some-module has the same effect.

As for concern of this topic and for my needs I think the script can be resumed as:

# remove bundled ImageMagick
sudo apt remove imagemagick -y

# install base dependencies
sudo apt-get install -y libheif-dev libwebp-dev

# installing
git clone --depth 1 --branch 7.1.0-14 https://github.com/ImageMagick/ImageMagick.git
cd ImageMagick

./configure --with-heic --with-webp

make -j 8
sudo make install
sudo ldconfig /usr/local/lib

# check
identify --version

@hurricup
Copy link
Author

hurricup commented Mar 22, 2022

@SorinGFS yes, but defaults may change from version to version, I've made this script independent from defaults. And some dependencies may not be installed for some reason. Even my script is incomplete, because I've had some of deps already.

@joelotz
Copy link

joelotz commented Apr 2, 2022

Worked great for me, thank you!

@rootwork
Copy link

rootwork commented Apr 23, 2022

This worked for me awhile back, but recently I tried it on a new machine running Linux Mint 20.3 (based on Ubuntu) and for some reason despite having removed the imagemagick package in the first step, identify --version at the end returned the old version number.

I did some digging and discovered that while magick was loading the new version, there were old versions of identify, convert and mogrify in my /usr/bin directory that were being called whenever I used those commands. The new ones were all in /usr/local/bin.

According to my $PATH, /usr/local/bin should override identical commands in /usr/bin, and I'm not sure why they didn't. But the quick fix was just to sudo rm the versions in /usr/bin.

In case anyone else encounters this...

@hurricup
Copy link
Author

  • Updated to 7.1.0-47
  • Added build-essential explicit installation
  • Explicitly enabled flif disabled by default
  • Tested with wsl ubuntu

@hurricup
Copy link
Author

hurricup commented Oct 12, 2022

  • Added few more dependencies for clean machine

@hurricup
Copy link
Author

  • Updated to 7.1.0-51

@hurricup
Copy link
Author

  • Updated to 7.1.0-52

@hurricup
Copy link
Author

hurricup commented Dec 5, 2022

  • Updated to 7.1.0-53

@hurricup
Copy link
Author

  • Updated to 7.1.0-54

@EarlSven
Copy link

Nice script. Might want to add git to the list of dependencies at the top of the script though, I was running this on a fresh Mint box and it failed due to lack of git.

@hurricup
Copy link
Author

Nice script. Might want to add git to the list of dependencies at the top of the script though, I was running this on a fresh Mint box and it failed due to lack of git.

Added git. Thank you.

@iskrisis
Copy link

iskrisis commented Apr 7, 2023

Does anybody know how to properly generate some default configs for imagemagick and where should they go? Without them and installing from source it might be pretty sketchy when you resize big images.

@hurricup
Copy link
Author

hurricup commented Apr 7, 2023

@iskrisis feels like IM repo is proper place for such question

@bwhaley
Copy link

bwhaley commented May 11, 2023

Thank you for this script. Saved me a bunch of time!

@kampelmuehler
Copy link

I was only having success with AVIF support using imei https://github.com/SoftCreatR/imei on ubuntu 20.0.4

@maartenterpstra
Copy link

If the make step fails with an error like:

/usr/bin/sed: can't read 1/ImageMagick/MagickCore/libMagickCore-7.Q16HDRI.la: No such file or directory
libtool:   error: '1/ImageMagick/MagickCore/libMagickCore-7.Q16HDRI.la' is not a valid libtool archive
make[1]: *** [Makefile:7294: MagickWand/libMagickWand-7.Q16HDRI.la] Error 1

libtool does not work with directories containing spaces. Ensure you compile ImageMagick in a directory such that the full path does not contain a space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment