Imagemagick on Ubuntu
Command
1
2
3
4
5
6
7
8
9
10
11
12 | list formats:
convert -list format
convert JPG to PNG:
convert input.jpg output.png
convert all JPGs to PNGs:
mogrify -format png *.jpg
convert SVG to PNG at 1000 DPI:
convert -density 1000 -units PixelsPerInch input.svg output.png
compress JPG to quality 50% width 1000:
convert input.jpg -quality 50% -resize 1000 output.jpg
compress all JPGs to quality 50% width 1000:
mogrify -quality 50% -resize 1000 *.jpg
|
Ref.http://academy.cba.mit.edu/classes/computer_design/image.html
Failure
I tried some versions on imagemagick, but the default installed version seems not support .HEIC format. I need to convert HEIC to jpeg format for my pictures taken by iphone.
Default installed magick on ubuntu(command is located in /usr/bin/convert
) : Not support HEIC
| $ /usr/bin/convert --version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
$ /usr/bin/convert ubuntu-install1.heic ubuntu-install1_test.jpg
convert: no decode delegate for this image format `HEIC' @ error/constitute.c/ReadImage/504.
convert: no images defined `ubuntu-install1_test.jpg' @ error/convert.c/ConvertImageCommand/3258.
|
The latest magick at imagemagick.org: NO support HEIC format.
Download Linux Binary Release magick , portable package from website.
| $ cd Downloads
$ ./magick --version
Version: ImageMagick 7.0.10-62 Q16 x86_64 2021-02-07 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC OpenMP(3.1)
Delegates (built-in): bzlib djvu fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr png raqm tiff x xml zlib
$ ./magick convert ubuntu-install1.heic ubuntu-install1_magick.jpg
convert: no decode delegate for this image format `HEIC' @ error/constitute.c/ReadImage/572.
convert: no images defined `ubuntu-install1_magick.jpg' @ error/convert.c/ConvertImageCommand/3304.
|
Even a version of downloaded portable package of magick is ImageMagick7, I could not convert .heic file as a input image.
Solution
As per a blog (ref. How to insatll iomageMagick 7 on Ubuntu about the same problem as above, I built and add libraries for converting .heic files as below.
1. Edit sources
Edit /etc/apt/sources.list
and add deb
(archive contains binary packages) and deb-src
(source packages) at the bottom of the file.
/etc/apt/sources.list
| # deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse
deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
|
Then update apt.
2. Build ImageMagick dependencies
Make sure all of ImageMagick 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
Add required the other libraries(libheif and libde265) as PPAs to repositories and install them to support heic files.
| $ 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
|
Download and install ImageMagick7.cd into /opt
, do configuration as with-heic=yes
and install. The version of ImageMagick-7.0.11-0
is the latest one as of 16 Feb 2021.
| $ cd /opt
$ sudo wget https://www.imagemagick.org/download/ImageMagick-7.0.11-0.tar.gz
$ sudo tar xvzf ImageMagick-7.0.11-0.tar.gz
$ cd ImageMagick-7.0.11-0
$ sudo ./configure --with-heic=yes
$ sudo make
$ sudo make install # $ `sudo checkinstall` may work here if you have that.
$ sudo ldconfig /usr/local/lib # this creates the necessary links and cache to the most recent shared libraries in /usr/local/lib
|
Then you reopen terminal, you should have:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | $ which magick
/usr/local/bin/magick
$ which convert
/usr/local/bin/convert
$ convert --version
Version: ImageMagick 7.0.11-0 Q16 x86_64 2021-02-13 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff x xml zlib
# magic --version has the same output above
|
Success
Finally, imagemagick on ubuntu supported .heic files.
| $ convert ubuntu-install1.heic ubuntu-install1.jpg
$ ls
ubuntu-install1.heic ubuntu-install1.jpg
|
If you want batch conversion,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | $ mogrify -format jpg -resize 800x -quality 90% -strip *.heic
$ ls -alrt
total 22028
-rw-rw-r-- 1 tato tato 1783285 2月 16 01:42 ubuntu-install8.heic
-rw-rw-r-- 1 tato tato 3104249 2月 16 01:42 ubuntu-install7.heic
-rw-rw-r-- 1 tato tato 2763850 2月 16 01:42 ubuntu-install6.heic
-rw-rw-r-- 1 tato tato 3060560 2月 16 01:42 ubuntu-install5.heic
-rw-rw-r-- 1 tato tato 2216210 2月 16 01:43 ubuntu-install4.heic
-rw-rw-r-- 1 tato tato 2463248 2月 16 01:43 ubuntu-install3.heic
-rw-rw-r-- 1 tato tato 3169240 2月 16 01:43 ubuntu-install2.heic
-rw-rw-r-- 1 tato tato 3115121 2月 16 01:43 ubuntu-install1.heic
drwxr-xr-x 27 tato tato 4096 2月 17 12:14 ..
-rw-r--r-- 1 tato tato 103615 2月 17 23:22 ubuntu-install1.jpg
-rw-r--r-- 1 tato tato 124111 2月 17 23:22 ubuntu-install2.jpg
-rw-r--r-- 1 tato tato 97677 2月 17 23:22 ubuntu-install3.jpg
-rw-r--r-- 1 tato tato 98592 2月 17 23:22 ubuntu-install4.jpg
-rw-r--r-- 1 tato tato 112623 2月 17 23:22 ubuntu-install5.jpg
-rw-r--r-- 1 tato tato 117368 2月 17 23:22 ubuntu-install6.jpg
-rw-r--r-- 1 tato tato 116172 2月 17 23:22 ubuntu-install7.jpg
-rw-r--r-- 1 tato tato 67882 2月 17 23:22 ubuntu-install8.jpg
|
setup-imagemagick.sh on gitlab (need to access to gitlab.fabcloud.org)
Last update: April 12, 2021