LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to Linux Subscribe to Newsletters

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:

Two color version of the original image

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:

A foour-color dithered version.

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:

With added border.

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.




Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com