Tools like the GIMP (www.gimp.org) and similar graphical applications are great for modifying and manipulating images. Sometimes, however, they can be overkill for little things that need to be done, such as converting file types or resizing images. As well, a graphical tool can be time consuming and difficult to script, unlike CLI tools.

The ImageMagick suite (www.imagemagick.org) of programs allows you to manipulate images from the command-line, making it much simpler to convert large numbers of pictures or even for that single quick image conversion.

Some of the tools that ImageMagick includes are the convert tool, the composite tool, and the display tool.

The convert tool is used to convert pictures from one format or size to another. The easiest method is to simply convert an image from one format to another using:

$ convert image.jpg image.png

This will convert image.jpg from a JPEG to a PNG and save it as image.png. To convert and resize an image, use:

$ convert -size 50x50 image.jpg image.png

This will convert from JPEG to PNG format and resize the resulting image to 50x50 pixels. Likewise, you can use convert to rotate an image:

$ convert -rotate 90 image.jpg image.png

This will rotate the image 90 degrees and convert it to a PNG file. To manipulate the file and keep it in the same format:

$ convert -rotate 90 image.jpg image-new.jpg

To create a composite image, or layer one image above another, use the composite tool. For instance, to put logo.jpg in the top-left corner of image.jpg, you would use:

$ composite -gravity NorthWest logo.jpg image.jpg composite.jpg

This will layer logo.jpg over image.jpg in the top-right corner (NorthWest), and the resulting file will be named composite.jpg. Each edge of the picture is noted by direction: Top is North, bottom is South, right is East, and left is West. The composite tool respects transparent pixels, so using it is a great way to automatically tag all your photos with your name or Web site address.

These commands merely scratch the surface of what ImageMagick can do. ImageMagick is capable of creating new images, embedding steganography in pictures, and much more.

Open Sourcery This was published in Open Sourcery, check every Monday for more stories

Related links

Comments

1

ali - 05/03/07

2

omer - 14/04/07

I need it Image Magick

» Report offensive content

3

ali - 14/04/07

ali-1
ali - 05/03/07
convert

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

3

ali - 14/04/07

ali-1 ali - 05/03/07 convert ... more

2

omer - 14/04/07

I need it Image Magick ... more

1

ali - 03/05/07

convert123 ... more

Log in


Sign up | Forgot your password?

  • Staff XP stays on life support for longer

    This week's Roundup looks at Microsoft's decision to extend the life of Windows XP, the release of Microsoft Surface SDK, Firefox's new Geode plug-in, Yahoo's new tool -- Smush It and more. Read more »

    -- posted by Staff

  • Chris Duckett The good and truly awful celluloid depictions of computers

    Ever wonder why your lawyer uncle leaves the room whenever you turn over to Boston Legal? Or why your forensic science cousin can't stand crime drama? You know the answer: it’s the horrid trivialisation and dumbing down of an occupation to make it appear entertaining. Sometimes it is so unbelievable that it actually hurts and yelling at the screen is the only outlet. Read more »

    -- posted by Chris Duckett

  • Brendon Chase Apple's iPhone engineers to tour Sydney, Melbourne

    Aussie developers will be able to get up close and personal with some of the iPhone engineers in November to learn how to build applications for the platform. Read more »

    -- posted by Brendon Chase

What's on?