← Back to all posts

How to install ImageMagick 7 on Ubuntu 16.04

David Anderson | May 20, 2019

I recently had a need to convert heic image files to jpg using ImageMagick. On my computer I didn’t have to do anything different than what I’d normally do to convert an image from one format to another. This was working perfectly:

$ convert image.heic image.jpg

Unfortunately, when I tried to do the same thing on my production server I ran into an error.

$ convert image.heic image.jpg
convert: no decode delegate for this image format `HEIC' @ error/constitute.c/ReadImage/501.
convert: no images defined `image.jpg' @ error/convert.c/ConvertImageCommand/3210.

I realized that heic support was added to ImageMagick 7. I was using ImageMagick 7 on my computer, but my production server was using version 6.8.9 which was why I was experiencing the error. Easy enough, I’ll just update ImageMagick on the production server to version 7. Not so fast, after all.

The imagemagick package that is available through Ubuntu’s apt-get is for version 6.8.9, so in order to get version 7 installed, I had to install it from source.

The general steps I followed to do this were: 1. Edit apt/sources.list to make sure that the deb-src lines are uncommented 2. Build imagemagick dependencies buid-dep imagemagick 3. Add and install ppa for the libheif and libde265 packages that are required for ImageMagick7 4. Download, configure and install ImageMagick 7

See below for more detail!

1. Edit Sources

Ubuntu uses apt for package management. It uses a file that stores a list of repositories (or sources) from which packages can be obtained. That sources.list file is usually found in /etc/apt/sources.list and will look like this:

# deb cdrom:[Ubuntu-Server 16.04.3 LTS _Xenial Xerus_ - Release amd64 (20170801)]/ xenial main restricted

# deb cdrom:[Ubuntu-Server 16.04.3 LTS _Xenial Xerus_ - Release amd64 (20170801)]/ xenial main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted

The first word on each line, deb or deb-src, indicates the type of archive. Deb indicates that the archive contains binary packages (deb), the pre-compiled packages that we normally use. Deb-src indicates source packages, which are the original program sources. In my case the deb-src lines were commented out, and I uncommented them to instruct apt that it could download source files from there. You can learn more here.

$ vim /etc/opt/sources.list #open the file with your text editor and uncomment deb-src lines

# after saving the file retrieve the updated package lists:

$ sudo apt-get update

2. Build ImageMagick dependencies

Next you’ll want to make sure that all of ImageMagick’s dependencies are installed.

$ sudo apt-get build-dep imagemagick -y

3. Add and install ppa for the libheif and libde265 packages that are required for ImageMagick 7

In addition to the dependencies you installed in step 2, ImageMagick 7 requires two other libraries if we want to support heic files. Those libraries aren’t available in the main Ubuntu packages, so we need to install two PPAs (libheif and libde265). First add the PPA repositories and then install them.

$ sudo add-apt-repository ppa:strukturag/libheif
$ sudo add-apt-repository ppa:strukturag/libde265
$ sudo apt-get update
$ sudo apt-get install libheif-dev
$ sudo apt-get install libde265-dev

If you don’t have add-apt-repository you can also just add this repository manually to your sources.list file. Please note, this is NOT needed if you added and installed the libraries using add-apt-repository as shown above.

# /etc/apt/sources.list

# You'll need to change xenial to the version of Ubunut you're using. xenial is for 16.04

deb http://ppa.launchpad.net/strukturag/libheif/ubuntu xenial main 
deb-src http://ppa.launchpad.net/strukturag/libheif/ubuntu xenial main
deb http://ppa.launchpad.net/strukturag/libde265/ubuntu xenial main 
deb-src http://ppa.launchpad.net/strukturag/libde265/ubuntu xenial main

4. Download, configure, and install ImageMagick 7

Now we’re ready to download and install ImageMagick7. cd into /opt, download the specific tarball you want from the downloads page and then extract the files. Once you’ve extracted the files, run ./configure with the with-heic=yes flag, and then finally install.

$ cd /opt
$ sudo wget https://www.imagemagick.org/download/ImageMagick-7.0.8-45.tar.gz
$ sudo tar xvzf ImageMagick-7.0.8-45.tar.gz
$ cd ImageMagick-7.0.8-45
$ sudo ./configure --with-heic=yes
$ sudo make
$ sudo checkinstall
$ sudo ldconfig /usr/local/lib # this creates the necessary links and cache to the most recent shared libraries in /usr/local/lib

# confirm that everything went well! Run the convert command and you 
# should see something like...
$ convert --version
Version: ImageMagick 7.0.8-45 Q16 x86_64 2019-05-14 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.0)
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff wmf x xml zlib

And that should be just about it! We’ve installed ImageMagick 7 with the required libraries to convert heic images to jpg. If you had a previous version of ImageMagick installed via apt-get, that version is still available which may or may be what you want. I won’t go into detail about how you uninstall either version, but you’ll likely have both versions available from the command line.

ImageMagick 7 (which we just installed from source) will be available via /usr/local/bin/convert and the Ubuntu package ImageMagick version that was installed will be available at /usr/bin/convert. /usr/local/bin takes precendence in our $PATH variable, so therefore the “default” convert command will be from ImageMagick 7. You can run the convert command for the previous version by running it directly with usr/bin/convert.

# version 7.0.8 was installed from source is available directly
$ convert --version
Version: ImageMagick 7.0.8-45 Q16 x86_64 2019-05-14 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.0)
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff wmf x xml zlib

# version 6.8.9 was installed via apt-get and is available at /usr/bin/convert
$ /usr/bin/convert --version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib

Conclusion

If you’re using ImageMagick and need to convert heic image files to jpg, you’ll need at least ImageMagick version 7. The supported ImageMagick version that you get through Ubuntu apt-get is version 6.8.9, so you’ll need to download, configure, and install ImageMagick 7 from source. It’s a bit of longer process, but completely doable given the steps summarized above. Let me know if you run into trouble!

SUBSCRIBE

Drop your email in the box below to subscribe to my newsletter. Once per week you'll get Ruby/Rails tips, guides, job postings, and general thoughts from the web developer trenches.