ImageMagick

From LinuxReviews
Jump to navigationJump to search
ImageMagick
ImageMagic-logo.jpg
Original author(s)John Cristy
Developer(s)ImageMagick Studio LLC
Initial releaseAugust 1, 1990; 31 years ago (1990-08-01)
Stable release
7.0.10-28 / August 16, 2020; 16 months ago (2020-08-16)
Repositorygithub.com /ImageMagick/ImageMagick
Operating systemCross-platform
TypeImage manipulation
LicenseImageMagick License (GPL and DFSG compatible)
Websiteimagemagick.org
Org.kde.spectacle.svg

ImageMagick is a cross-platform suite of libraries, command-line tools and GUI tools for converting, creating, modifying and displaying digital image files. Several of the tools, like convert, are very handy if you need to convert, resize or otherwise modify an image or ten in a terminal. ImageMagick supports pretty much all the image formats, if it is a image file and you need to do something with it then ImageMagick will much likely be able to get the job done.

A lot of free software, including the MediaWiki content management system used on this website, use ImageMagick tools or libraries.

Image File Format Support[edit]

The list of image formats supported by ImageMagick is so long it is suffice to say that the changes of it not being able to open or save any random image file format is slim. Actual support does vary a bit from distribution to distribution, an old distribution like RHEL/CentOS 7.x will provide a ImageMagick package without WebP support while ImageMagick on any more modern distribution like Ubuntu 20.04 or Fedora 32 will support WebP and other more recent image formats.

A full list supported image formats can be seen by running

identify -list format

The Tools[edit]

ImageMagick is primarily a set of command-line tools for editing and manipulating images. The graphical image viewer display is the only exception. The ImageMagick package comes with the following binaries:

Tool Function Example Manual
animate Tool to display animations of animated images or a series of still images. animate *.png animate.1
compare Compare difference between an image and its reconstruction. compare.1
composite Overlap (combine) one image with another. composite inputfile1.png inputfile2.png outputfile.png composite.1
conjure Executes scripts written in the Magick Scripting Language.
Scripts can be pretty advanced.
conjure.1
convert Converts between different image file formats. Can also resize and do a lot more. Probably the tool you will end up using the most. convert bigresolutionfile.jpg -resize 200 twohundredpixelwide.jpg
Aspect ratio is kept and height is calculated correctly if only width is specified.
convert.1
display Simple old-school image viewer.


Wildly outdated. Useless on HIDPI displays.
Absolute garbage compared to geeqie and other more modern image viewer.

display.1
identify Shows an image files file type, resolution and color information. Can show information about video files too. identify image.jpg identify.1
import Take a screenshot of any X window or the root window (=the entire desktop) import -window root screenshot.jpg import.1
mogrify Tool to resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.


mogrify works on and overwrites the input file.

mogrify -flatten gifanimation.gif mogrify.1
montage Create a composite image using other images montage image1.jpg image2.jpg output.jpg montage.1
stream Stream one or more pixel components of the image to another storage format stream.1

Convert[edit]

convert is probably the most useful every-day tool in the ImageMagick suite. It lets you quickly convert an image or a series of images to another format.

The most basic usage is convert input.jpg -option argument outputfile.jpg. You do not need to use any option or argument if you just want to convert between two file formats:

convert file.jpg file.webp

Convert supports a lot of options like -rotate, -resize and a rather long list of other options. These are used like this:

convert file.jpg -resize 200 file.webp

convert file.jpg -rotate 90 file.webp

See convert --help or the convert.1 manual page for a list off all the other options. convert can do a lot beyond pure conversion between image formats. You can -combine images, -flip them and even -flatten images with layers or change layers using convert. It is easier to do many of the things it can using a graphical editor like the GNU Image Manipulation Program or KolourPaint, but those aren't very efficient if you want to process lots and lots of images and they are not suitable if you want to add image-related functionality to a program you are writing.

Batch processing images[edit]

convert itself does not support batch processing, each command need to have one (or more if you are making an animated image) input file and one output file.

Converting a directory full of .png images to .webp can be done using a simple loop:

for f in *.png; do convert $f ${f%.*}.webp ; done

The above command will run a series of convert commands, one for each .png image file in the current folder, and convert the png images to .webp (${f%.*} strips the file extension so webp replaces .png). Running a series of convert commands, one after another, is mush slower than running them in parallel if you are using a multi-core machine.

GNU Parallel can be used to batch process commands like convert. The following command will run convert on all .png files in a folder and create webp images:

parallel -j$(nproc) convert {} {.}.webp ::: *.png

The -j option specifies the number of parallel jobs ($(nproc) is magically the number of threads available on a Linux box), {} is replaced with the input filename, {.} is replaced with the input filename without the extension and ::: separates the command to be executed from the list of jobs to be processed (in this case all *.png images.

display[edit]

ImageMagick-display.jpg
The display program that comes with ImageMagick 6.9.11. Good luck seeing the text on that stamp-sized menu on a high resolution monitor.

Display is very simple graphical image viewer with an interface that does not scale to modern HIDPI monitors. It looks very much like something that has not been updated since ImageMagick was released in August 1990. It is pure garbage compared to most other image viewers.

OpenCL Support[edit]

ImageMagick has had support for using OpenCL, leveraging the OpenMP library API, for a very long time. However, major Linux distributions do not compile this support into the packages they distribute.

While ImageMagick can, in theory, use OpenCL it is not something that will be available unless you compile ImageMagick yourself.

You can check if your version supports OpenCL by running

identify -version |grep Features

If you compile your own version and you enabled OpenCL and everything went well then you will get something like: Features: DPC Cipher Modules OpenCL OpenMP(4.5)

The version your distribution ships will likely show something like

Features: Cipher DPC Modules OpenMP(3.1)

or

Features: Cipher DPC Modules OpenMP(4.5).

Note how OpenCL are not listed in these two examples. OpenMP, on the other hand, is present everywhere. OpenMP is therefore the better choice if you want to write some image-related application and leverage graphics cards using something like the ROCm framework.

Links[edit]

The ImageMagick website is at imagemagick.org.


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.