[ImageMagick]
[promote]

The ImageMagick command line can be as simple as

  convert image.jpg image.png

or as complex as

  convert label.gif +matte \
    \( +clone  -shade 110x90 -normalize -negate +clone  -compose Plus -composite \) \
    \( -clone 0 -shade 110x50 -normalize -channel BG -fx 0 +channel -matte \) \
    -delete 0 +swap  -compose Multiply -composite  button.gif

Without knowing much about ImageMagick, you can probably figure out that the first command converts an image in the JPEG format to one in the PNG format. However, very few may realize the second, more complex command, gives a flat two-dimensional label a three-dimensional look with rich textures and simulated depth:

label ==> button

In the next sections we dissect the anatomy of the ImageMagick command line. Hopefully after carefully reading and better understanding how the command line works, you will be able to accomplish complex image-processing tasks without resorting to the sometimes daunting program interfaces.

The Anatomy of the Command Line

The ImageMagick command line consists of

  1. one or more required input filenames.
  2. optionally, an image setting.
  3. optionally, an image operator.
  4. optionally, an image stack.
  5. optionally, an output filename (required by convert, composite, montage, compare, import, and conjure).

You can find an explanation of each of the constituent parts of the command line in the sections that follow.

Input Filename

ImageMagick extends the concept of a filename to include specifying an explicit image format, using built-in images and patterns, reading an image from standard in, selecting certain frames from an image, and selecting a region of an image.

    Explicit Image Format
    Images are stored in a mryiad of image formats including the better known JPEG, PNG, TIFF and others. ImageMagick must know the format of the image before it can be read and processed. Most formats have a signature within the image that uniquely identifies the format. Failing that, ImageMagick leverages the filename extension to determine the format. For example, image.jpg tells ImageMagick it is reading an image in the JPEG format. In some cases the image may not contain a signature and/or the filename does not identify the image format. In these cases an explicit image format must be specified. For example, suppose our image is named image and contains raw red, green, and blue intensity values. ImageMagick has no way to determine the image format so we explicitly set one, rgb:image.

    Built-in Images and Patterns
    ImageMagick has a number of built-in images and patterns. To utilize the checker board pattern, for example, use:
      convert -size 640x480 pattern:checkerboard checkerboard.png
    


    Standard In
    Unix and Linux permits the output of one command to be piped to another. ImageMagick permits piping one command to another with a filename of -. In this example we pipe the output of one convert to another:
        convert magick:logo gif:- | convert gif:- image.jpg
      
    Here the explicit format is optional. The GIF image format has a unique signature within the image so ImageMagick can readily recognize the format as GIF.

    Selecting Frames
    Some images formats contain more than one image frame. Perhaps you only want the first image or the last or some number of images in-between. You can specify which image frames to read by appending the image filename with the frame range enclosed in brackets. Here out image contains more than one frame but we only want the first:
        convert images.gif[0] image.png
      
    Unix shells generally interpret backets so we must enclose the filename in quotes:
        convert 'images.gif[0]' image.png
      
    You can read for than one image from a sequence with a frame range:
        convert 'images.gif[0-4]' images.mng
      
    Finally, you can read more than one image from a sequence out-of-order:
        convert 'images.gif[3,2,4]' images.mng
      
    This reads the third image in the sequence followed by the second and than the fourth.

    Selecting an Image Region
    Raw images are a sequence of color intensities without additional meta information such as width, height, or image signature. With raw image formats, you can specify a region of the image to read. In out example, the image is in the raw RGB format and is 6000 pixels wide and 4000 pixels high. However, we only want a region of 600 by 400 near the center of the image:
        convert -size 6000x4000 -depth 8 'rgb:image[600x400+1900+2900]' image.jpg
      
    You can get the same results with the -extract option:
        convert -size 6000x4000 -depth 8 'rgb:image' -extract 600x400+1900+2900 image.jpg
      

Image Setting

...

Image Operator

...

Image Stack

...

Output Filename

...

 
© 1999-2005 ImageMagick Studio LLC