(Modified 2011 Dec 16)
ImageMagick
convert
convert
The convert command converts or resizes an image from the command line. One simple use would be to convert an image from PNG to JPG format, e.g.:
convert in.png out.jpg
I wrote a batch script called png2jpg to convert a series of images. To convert a series of images, the syntax is:
png2jpg "imageseries*"
I also added an option to use non-default formats, other than PNG/JPG:
png2jpg "imageseries*" bmp tif
Resizing
Another common use for me is to shrink photos that are way too big, in terms of both dimensions and memory, to display quickly on my palmtop (formerly a Zaurus SLC1000, and now a Nokia N810). Here's the syntax:
convert in.jpg -resize 640x480 out.jpg
The image will not be stretched to the specified dimensions. Rather, the aspect ratio will be held constant, and the image will be scaled down to fit inside a 640x480 box. Images already smaller than the box will not be resized.
I wrote a batch script called shrink to resize a series of images. To resize a series of images, the syntax is:
shrink "imageseries*jpg" target_directory 640x480
Compression
One of my cameras doesn't compress images enough, so I use the following:
convert in.jpg -quality 92 out.jpg
The compression level ranges from 0 (smallest output size) to 100 (largest). 92 is the default.
I wrote a batch script called compressjpgfromdoc to compress a series of images. The syntax is:
compressjpgfromdoc indoc.txt 92
indoc.txt is a text file with one entry per line, and 92 is the (optional) compression level.
Screen capture
I adapted the following from inspirated.com.
The command xwd is a ubiquitous one that captures the contents of windows. However, many common image-viewers cannot read the XWD format. The command to write to an arbitrary format, using Imagemagick's convert, is:
xwd | convert xwd:- capture.png
The output format can be altered by simply changing the extension. In contrast to the blog entry above, with this usage, you still have to click on the window to be dumped.
There are plenty of other options for convert. See the manual page for details.
This page is Lynx-enhanced