Linux Blog

Command Line Image Editing with ImageMagick

Filed under: Linux Software — at 1:52 pm on Friday, February 13, 2009

Image Magick

Image editing is often considered a pitfall of the Linux desktop. When I was in school a number of years ago a Windows user (that later converted to the hipster OS X “better than thou” type) said to me:
“I don’t know why any one uses the command line anymore, it’s obsolete”
People often forget about the power of the command line. The command line may not be the best utility for everything but image editing is a shining example of how it can be used. I wouldn’t recommend trying to type a command that touches up your photos, but any operation that has to be repeated a number of times can be easily accomplished through a series of commands.

While there are many command line image editing tools available, this post focuses on the ImageMagick suite. While all of this can be read in the man page I aim to simplify and document for both myself and other casual ImageMagick users. By far the most valuable resource for ImageMagick is the online documentation.

Basically ImageMagick takes a number of parameters depending on the function you are to perform. Most commonly an input filename, an operation and an output filename. You can specify the same filename for both input and output in most cases, unless you are trying to keep the source image in its original form.

Here are some of my favourite and most used functions of imagemagick:

Resize an image
To resize an imagemagick is very simple. Using convert you specify the -resize option. You have several options when resizing, resize by width or height. You can also resize while adding a background color if your image has strange dimensions

Rotate an Image
Rotating an image is a snap, using convert with the source file -rotate <degrees> out file you can rotate by any number of degrees. 90, 180, 270 are most common, to change orientation but other angles may be used. Keep in mind that you may want to set a background color to do this.

Flipping an image
There are two ways to flip and image and they get sort of confusing. Imagemagick uses -flip for vertical images and -flop for horizontal flipping.

Adjusting the quality of an image is sometimes desirable for saving files to the web. Use -quality <0-100> (100 being the best) to adjust the quality

Working with GIFS
Gif’s can be edited or created by those patient enough to do so. The major think about working with gifs is the -coalese option. This takes each frame from the gif and makes it its own image. Be careful when using this as it will make Filename.gif Filename-1.gif, Filename-2.gif, Filename-3.gif and overwrite those files if they already exist. You can then work on each frame individually, or with a script and then join them back together.

Add Voice to your Shell Scripts

Filed under: Shell Script Sundays — at 3:52 pm on Sunday, October 12, 2008

Text to speech has been around for a number of years. While you may not want to add text to speech to all of your shell scripts you may have a particular script that would be nice to get some audio feedback from. There are a couple of text-to-speech engines that run in the shell, but my favorite is flite. It is really simple to install and use and has a decent set of voices. You can add other voices or compile your own with FestVox.

Here is how to use flite from the shell to directly play the text:

[owen@TheLinuxBlog ~]$ flite -t “Thanks for reading The Linochs Blog”

Notice the misspelling of the word Linux. If flite doesn’t correctly output the words, you can sometimes use phonetics to get a better result.

You can also play text files by using the -f option.

[owen@TheLinuxBlog ~]$ flite -t “Thanks for reading The Linochs Blog”
flite: pcm_params.c:2333: sndrv_pcm_hw_params: Assertion `err >= 0′ failed.

(Read on …)