ImageMagick's Convert

ImageMagick's convert utility is a great way to process images on *nix machines. You can handle images in batches to, say, resize and convert an entire folder down to web-friendly jpgs, or do some more complex things like add drop shadows to images, combine multiple images into one, and so forth and so on.

The configuring and installing process for ImageMagick is fairly simple and well-documented. However, you can't just configure, make, install your way into drop shadow-ing images on the fly. The main thing you have to be aware of is that ImageMagick, unlike some other multi-media utilities like ffmpeg, doesn't include all the necessary libraries you need to do what you want.

After running downloading and expanding the ImageMagick tarbar, run ./configure to find out what you’ll need to install. After it finishes, you’ll see a section like this:

Delegate Configuration:
BZLIB             –with-bzlib=yes              yes
DJVU              –with-djvu=no                no
DPS               –with-dps=yes                no
FlashPIX          –with-fpx=yes                no
FontConfig        –with-fontconfig=no          no
FreeType          –with-freetype=yes           no
GhostPCL          None                          pcl6 (unknown)
GhostXPS          None                          gxps (unknown)
Ghostscript       None                          gs (unknown)
result_ghostscript_font_dir=‘none’
Ghostscript fonts –with-gs-font-dir=default
Ghostscript lib   –with-gslib=yes              no
Graphviz          –with-gvc=yes                no
JBIG              –with-jbig=yes               no
JPEG v1           –with-jpeg=yes               yes
JPEG-2000         –with-jp2=yes                yes
LCMS              –with-lcms=yes               no
LQR               –with-lqr=no         no
Magick++          –with-magick-plus-plus=yes   yes
OpenEXR           –with-openexr=yes            no
PERL              –with-perl=yes               usrbin/perl
PNG               –with-png=yes                yes
RSVG              –with-rsvg=no                no
TIFF              –with-tiff=yes               yes
result_windows_font_dir=‘none’
Windows fonts     –with-windows-font-dir=
WMF               –with-wmf=yes                no
X11               –with-x=                     no
XML               –with-xml=no         no
ZLIB              –with-zlib=yes               yes

The main things to look for are JPEG v1, JPEG-2000, PNG, and TIFF (those being the most common images formats). If those items in the list say “yes” in the column to the right, go ahead and make install. Otherwise, you’ll have to download libpng for PNG support, libjpeg for JPEG support, and libtiff for TIFF support.

Newbie Alert: If, after configure, make, make install of all the libraries, ImageMagick still isn't seeing the support for them, it's most likely because the /usr/local directory isn't in the PATH. If you're nervous about changing the PATH, you can instead install these libraries into /usr:

./configure –prefix=/usr

Note: If you know what you’re doing and you know that your local directories are in the PATH, ignore this last recommendation and the libraries will install to /usr/local, and ImageMagick will know to look there.

To Add a Drop Shadow: Assuming you have PNG and JPEG support, you can use this command to add a drop shadow to an image:

convert {ORIGINAL_FILE}.jpg -quality 90 ( +clone -background black -shadow 75x3+4+5 ) +swap -background \“#FFFFFF\” -layers merge +repage {OUTPUT_FILE}.jpg

That will add a 75% opaque drop shadow. You can play with the 3, 4, and 5 numbers to adjust the x/y offset and location of the drop shadow.

Note: There are a few links out in the interweb that incorrectly say that it should be `-background none`. Be aware that this, when combining back down into a jpg will create an all-black image. For PNGs, `-background none` is fine, since it supports transparency, but you should specify the background color the shadow is "dropping" to for jpegs.

 
comments powered by Disqus