Cheat Logo

Cheat Sheet

Hints for ImageMagick

  1. Compressing image files
  2. Labeling Images
  3. Turn a PDF into page thumbnails
  4. Wallpaper script

Compressing image files

Last updated: 2011-08-10
Level: Intermediate
OS:
  • Windows
  • OS X
  • Linux
  • BSD
  • Solaris

Different programs can produce surprisingly divergent results when exporting pictures for the web. For example, for two thumbnail images of book covers I recently posted there was a 3x size difference depending on which program I used. One of the images took 1/3 the space when compressed using Preview.app, the other when using ImageMagick. It's good that I looked at the file sizes before posting, and knew to try another program.

If the image you are compressing is a PNG, try pngcrush. Depending on the image, you can usually save about 15% of the filesize.

Labeling Images

Last updated: 2010-09-27
Level: Intermediate
OS:
  • OS X
  • Linux
  • BSD
  • Solaris
Programs:

Add label to southeast corner:

convert -font Verdana-Regular -pointsize 9 -background '#00000080' \
 -fill lightblue label:'schutt.org' miff:- | composite -gravity southeast \
 -geometry +0+0 - in.png  out.png

Add text to bottom:

montage -geometry +0+0 -font Verdana-Regular -pointsize 9 \
 -background 'gray(20%)' -fill skyblue \
 -label "Some text goes here" in.png out.png

Turn a PDF into page thumbnails

Last updated: 2010-06-11
Level: Intermediate
OS:
  • OS X
  • Linux
  • BSD
  • Solaris
Tags:
Programs:

To create thumbnails of every page in a PDF:

convert -geometry 180x180 -trim in.pdf out.png

To tile the thumbnails:

montage -tile 6x -geometry +0+0 *.png combined.png

Wallpaper script

Last updated: 2010-06-11
Level: Intermediate
OS:
  • OS X
  • Linux
  • BSD
  • Solaris
Programs:

When using a small image as a desktop wallpaper, it is often useful to expand the image background to fill the full screen. This script finds the background color of the original image, then expands it to the specified size. The shave statement is used for images with a one pixel border.

#!/bin/bash
# get colour
colour=`convert $1 -crop 1x1+1+1 txt:- | sed -n 's/.* \(#.*\) .*/\1/p'`
# crop & expand
mogrify -shave 1x1 -extent $2 -background $colour -gravity center $1
©2015 Schutt Design (Luke & Noel Schutt).
Contact us using one of our first names at schuttdesign dot net.