Nicolas Even

Using ImageMagick to make sharp web-sized photographs

ImageMagick is a command-line program that can do many operations on images quickly and with high quality. It's especially useful for resizing and sharp­ening images before publishing them on a site or forum, making thumbnails, etc.

Why sharpen?

When downsized, photographs tend to appear dim and blurry. Here's an example :

Col de l'Iseran - not sharpened

If you hover the mouse on the image, you'll see the sharpened version. Much better isn't it? You can especially see the letter on the sign pop out, and the image is globally easier on the eyes.

How to get a sharp, web-sized picture from your camera file?

Here's the command I ran to get the sharp photo above from the original high‐resolution file :

gm convert P1020592.jpg -resize "600x" -unsharp 2x0.5+0.7+0 -quality 98 iseran_s.jpg

What does it do ? It takes the high-res P1020592.jpg, resizes-it to 600px wide, sharpens it, and saves it as a 98 quality JPEG in iseran_s.jpg. That's all. Now all you have to do is install the "graphicsmagick" (newer, better, faster) or "imagemagick" package on your box.

Note : if you choose to use imagemagick rather than graphicsmagick, just remove the "gm " at the beginning of the command.

How to tweak the unsharp mask function?

The function we use for sharpening is called unsharp mask. Here's the syntax :

-unsharp RadiusxSigma+Amount+Threshold

The problem is it's not really self-explanatory, even when reading the manual. So, here's a simple explanation :

So, to sum up : start with the command I gave above and adjust the Sigma and Amount until you get something you like.

The thing that can be confusing is that in most other software, the radius is an important setting. In imagemagick, it's sigma you should set instead (and just keep Radius a little higher than sigma). If you only set Radius, things won't work as expected.

How do I resize a whole folder of images?

Here's a command you can use :

ls *.jpg|while read i;do gm convert $i -resize "900x" -unsharp 2x0.5+0.5+0 -quality 98 `basename $i .jpg`_s.jpg;done

It will resize all the .jpg files in the folder, saving the small versions with a "_s" at the end of the filename.