Transforming Images
Pages: 1, 2
Reducing the colors in an image
To reduce the number of colors in an image, use the -colors option
followed by the number of colors to use.
To reduce the colors in the original image to two, type:
mogrify -colors 2 penguin.jpeg
This changes the penguin.jpeg image to:
![]()
To reduce the colors with Floyd-Steinberg error diffusion, add the
-dither option; dithering an image typically improves image quality
when the number of image colors must be reduced. You can also use the -map option
with a second filename as an argument to use the set of colors in the
second file as the "color map" used in the first.
To reduce the number of colors in the original penguin.jpeg to four and
dither the image, type:
mogrify -colors 4 -dither penguin.jpeg
Resulting in:
Use the -monochrome option to turn a color image into a monochrome
one.
For example, to make the original penguin.jpeg file monochrome, type:
mogrify -monochrome penguin.jpeg
Annotating an image
Use the -comment option followed by a comment in quotes to annotate a
JPEG image file with a comment. This option is useful for adding
copyright (or copyleft) comments in a file, or for annotating a
file with a URL.
For example, to annotate our sample file, type:
mogrify -comment 'See http://oreilly.linux.com/' penguin.jpeg
You don't see the annotation when you view the image itself; the
annotation is added to the image header in the file. You can read
annotations with tools that display information about an image file,
such as display or the GIMP; for JPEG files, you can also use
the rdjpgcom tool -- it outputs any comments in the JPEG
file given as an argument.
To read any comments saved in the image file penguin.jpeg, type:
rdjpgcom penguin.jpeg
See http://oreilly.linux.com/
Adding borders to an image
To draw a border around an image, use the -border option followed
by the width and height, in pixels, of the border to use.
For example, to add a border two pixels wide and four pixels high to
the original penguin.jpeg, type:
mogrify -border 2x4 penguin.jpeg
This changes the penguin.jpeg image to:
![]()
Note that the border is appended to the outside of the existing image; that is, none of the existing image is cropped to add the border.
The -frame option works just like -border, but it gives a more "decorative" border to an image.
For example, to add a decorative frame twenty pixels wide and
twenty pixels high to the original penguin.jpeg, type:
mogrify -frame 20x20 penguin.jpeg
This changes the penguin.jpeg image to:

Next week: using a scanner with Linux.
Michael Stutz was one of the first reporters to cover Linux and the free software movement in the mainstream press.
Read more Living Linux columns.