Image Editing for Power Users on the Mac

by Devanshu Mehta Oct 11, 2007

ImageMagick is an extraordinarily powerful open source package that contains many different utilities to edit and create images. With a single line on the command line, you can rotate, resize, merge, convert, and subtitle a collection of images. You can get started right away—once you’ve installed ImageMagick—with fairly simple commands, such as the first “convert” example below. But once you get comfortable with it, it could even replace your trusty (bloated!) image editor.

To install ImageMagick, you will need either Fink or MacPorts, or follow the “Mac OS X Binary” installation instructions on the ImageMagick web site. To get started with Fink, try my earlier article about using Fink.

Each of these commands needs to be run on the command line in an application like Terminal.app. Remember, to explore any command in detail, you can either type “man “ (e.g. man convert) on the command line or visit the extensive ImageMagick online help.

Converting File Formats
With ImageMagick, converting the file format is as simple as giving it a new file name with the “convert” command. The following will convert a JPG file named xyz.jpg into a TIFF named xyz.tiff.

convert xyz.jpg xyz.tiff

Replace “tiff” with “gif,” “png,” or any other popular image format to convert it to that format.

Create Thumbnails in an Instant
Creating thumbnails of images in most image editors requires a few clicks, and editing them in bulk is harder than pulling each hair out of your scalp individually.

With ImageMagick:

convert xyz.jpg -resize 50% xyz50.jpg

That will change the image xyz.jpg to 50% its original size and name the newly created file xyz50.jpg. The “convert” command will always create a new image file, and the last argument supplied to it will be its name.

convert xyz.jpg -resize 50x50 xyz5050.jpg

The command above will change it to a 50x50 thumbnail.

You can combine different ImageMagick options like this:

convert xyz.jpg -resize 50% xyz50.png

Rotate a Set of Images
Rotating an image is just as simple. In the example below, “-rotate 30” means rotated 30 degrees in the clockwise direction.

convert xyz.jpg -rotate 30 xyz30r.jpg

Of course, it is more likely that you will want to rotate your photograph by 90 or 270 degrees, but no one is stopping you from being quirky.

To Add a Subtitle or Text Caption
Sometimes you just want to add a little text to your image. This can be done with most GUI image editing tools, but not quite as simply as with ImageMagick—especially if you want to add the same text to many images. Examples of such a situation would be a watermark with the source of the image, a subtitle with the album name, or a copyright notice.

convert xyz.jpg -draw “text 10,10 ‘Nifty Text!’” xyzNifty.jpg

This command will add the text “Nifty Text!” to the image xyz.jpg at the coordinates (10,10) which are calculated from the top left corner. You can even specify font and point size to make your text more or less pronounced.

convert xyz.jpg -draw “text 10,10 ‘Nifty Text!’” -font Courier -pointsize 35 -stroke white xyzNifty.jpg

Again, if you play around with these tools more, your powers will increase. But remember, with great power…

Create Text Banner
Creating a banner in ImageMagick is also fairly simple. This time you would use the convert command without an actual source file.

convert -size 200x40 xc:transparent -font Courier -pointsize 20 -channel RGBA -gaussian 0x6 -fill darkred -stroke magenta -draw “text 10,30 ‘My Nifty Banner!’” nifty-magick.png

This example will create a new transparent image sized 200x40, and type the magenta text “My Nifty Banner!” at coordinates (10,30). You can see how far you can get with a few options, and the “convert” command has many more.

Create a Montage
ImageMagick also comes with the “montage” command which allows you to create—you guessed it—a montage of all the images you specify. In addition to simply “montaging” them, you can give it a background and border and each image a caption.

montage -background black -border 1 -label %f *.jpg montage.jpg

It is slightly self-explanatory, but the command above will create a montage of every JPG image in the current directory, with a black background and call it montage.jpg. The “-label %f” gives each image a label with its file name and “-border 1” gives it a thin border.

Get Information About an Image
Simply type the following to get some basic information about an image. To get a really large amount of information, including EXIF data (e.g. from your camera):

identify xyz.jpg

To get a lot more detailed information about the image, try the following:

identify -verbose xyz.jpg

Here’s an excerpt of the “identify” data from one of my images:

[...]
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 1600x1200+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 93
Orientation: TopLeft
Exif:ColorSpace: 1
Exif:DateTime: 2007:10:03 22:55:49
Exif:DateTimeDigitized: 2007:10:03 20:35:52
Exif:DateTimeOriginal: 2007:10:03 20:35:52
Exif:ExifImageLength: 1200
Exif:ExifImageWidth: 1600
Exif:ExifOffset: 213
Exif:ExifVersion: 0220
Exif:FNumber: 14/5
Exif:Make: Apple
Exif:Model: iPhone
Exif:Orientation: 1
[...]

There is actually three times as much information as is displayed.

Bulk Actions on Image Files

In many cases, the *.jpg type wildcard will suffice to perform actions on a large number of files. For example,

mogrigy -resize 200x200 *.jpg

This will resize every single JPG image in the directory to a 200x200 size and retain their names. This will overwrite the original image, so be careful. If you want to create a new file, you can use the “convert” command mentioned above. In order to use the “convert” command on a large number of files, we will have to script a bit.

for image in `ls *.jpg`
do
convert $image -resize 200x200 size200-$image
done

This should be easy to read if you have programmed before, but even otherwise, it is fairly English-like. Basically, it will take every JPG file in the current directory, resize it to 200x200, and rename it with the prefix “size200-.” Edit it and test it on some images you can afford to mangle. This is great for creating thumbnails for a web site or smaller sized images to email.

Comments

  • att: webmaster

    where is the print command?

    when readers save an article, they need to be able to discard the non-editorial elements (navbars, adverts etc) ... and the print command is often the only effective way to strip out all the flotsom from the saved file that would otherwise pollute the (desktop/enterprise) search space with extraneious keywords.

    btw: please implement the ‘print’ view of the DOM with proper css3/xhtml2 or at least html5 .... NOT with javascript (many people now browse with jscript and actionscript disabled because they are usually buggy & also are a HUGE waste of cpu resources).

    Canada zahadum had this to say on Oct 11, 2007 Posts: 6
  • Page 1 of 1 pages
You need log in, or register, in order to comment