ImageMagick

Updated: 02/27/2019 by Computer Hope
ImageMagick wizard mascot

ImageMagick is an open-source suite of command line tools for manipulating digital images. It is useful for batch processing numerous images, or to quickly perform precise image modification tasks.

ImageMagick can be downloaded from its official website, ImageMagick.org.

History

Development of ImageMagick began in 1987, authored by software engineer John Cristy. Today, ImageMagick is a default component of many Linux and BSD (Berkeley Software Distribution) operating systems, and is freely available for Microsoft Windows, macOS, and iOS.

Features and tools

ImageMagick's features are divided into individual tools, each with a command.

Command Description
animate Display an image sequence as an animation.
compare Analyze two images, and visualize mathematical differences between them.
composite Compose one image over another with variable transparency to create a composite image.
conjure Interpret and execute scripts written in MSL, the Magick Scripting Language.
convert Convert images from one file format to another. This tool can also blur, crop, despeckle, dither, and otherwise modify the content of an image.
display A simple image viewer.
identify Display the image dimensions, quality, and other image metadata.
import Capture the screen to an image file.
mogrify Modify an image. Like convert, but overwrites the original image.
montage Create an image composed of smaller images. This command can create a single image containing thumbnails of many images.
stream Process image data and store it to a file as it is being streamed from an input source. Useful for situations with slow data streams, or large images whose data processing should begin before the entire image is stored.

In version 7 of ImageMagick, these tools can be accessed with the magick command, for example magick compare. Also, the script interpreter can be accessed with magick-script.

The commands animate, display, and import require an X server (the X Window System) to function. If you're not using Linux or BSD, you can run these commands on macOS with XQuartz, or on Microsoft Windows with VcXsrv.

Example commands

The following are sample commands you can use with ImageMagick.

Example 1: Resize image, specify image quality

 convert myimage.jpg -resize 25% -quality 92 output1.jpg

Reduce the image size by 25%, and save it at 92% image quality, as the file output1.jpg.

input.jpg output1.jpg
Input: Computer Hope logo, 200 x 200 pixels. Output2: Computer Hope logo, 50 x 50 pixels.

Example 2: Scale and rotate image data

 convert input.jpg -distort SRT .5,135 output2.jpg

Use the -distort SRT (scale, rotate, translate) distortion type to scale the image 50%, and rotate it 135 degrees clockwise. The dimensions of the final image remain the same, padded with the default color white.

input.jpg output2.jpg
Input: Computer Hope logo, 200 x 200 pixels. Output 2: Computer Hope logo, 200 x 200 pixels, image contents scaled 50% and rotated 139 degrees clockwise.

Example 3: Add a swirl effect, resize

 convert input.jpg -swirl 720 -resize 120% output3.jpg

Swirl the image 720 degrees and resize it to 120%.

input.jpg output3.jpg
Input: Computer Hope logo, 200 x 200 pixels. Output 3: Computer Hope logo, 240 x 240 pixels, swirled 720 degrees.

Example 4: Create a montage of image thumbnails

 montage -label '%f' input.jpg output*.jpg -frame 3 -background '#2B81EE' montage.jpg

Create an image with thumbnails of input.jpg and all output images (using the wildcard *). The options specify a file name label, a frame of 3 pixels, a blue background color, and the output file name montage.jpg. Each thumbnail is scaled differently.

montage.jpg
Montage: The input image, and three output images, displayed with file names, in a single image.

Example 5: View file metadata

 identify *.jpg

Display file data for all jpg images in the current directory.

 input.jpg[1] JPEG 200x200 200x200+0+0 8-bit sRGB 17.5KB 0.000u 0:00.000
 montage.jpg[3] JPEG 268x296 268x296+0+0 8-bit sRGB 26.1KB 0.000u 0:00.000
 output1.jpg[4] JPEG 50x50 50x50+0+0 8-bit sRGB 2.99KB 0.000u 0:00.000
 output2.jpg[5] JPEG 200x200 100x100+0+0 8-bit sRGB 10.4KB 0.000u 0:00.000
 output3.jpg[6] JPEG 240x240 240x240+0+0 8-bit sRGB 37.1KB 0.000u 0:00.000

Documentation and additional information

ImageMagick documentation, including extensive examples, is on their official website.

2016 Vulnerability

In 2016, major security vulnerabilities were discovered in the way ImageMagick processes file names. Nicknamed "ImageTragick," these security holes potentially allowed RCE (Remote Code Execution) by an attacker on the server. Thousands of websites were affected, but the vulnerabilities were quickly mitigated and patched.

A complete list of CVEs for ImageMagic is located at CVEDetails.com.

Command line, Digital image, IM, Script, Software terms