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 sharpening images before publishing them on a site or forum, making thumbnails, etc.
When downsized, photographs tend to appear dim and blurry. Here's an example :
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 :
The problem is it's not really self-explanatory, even when reading the manual. So, here's a simple explanation :
- Radius : that's the maximum distance (in pixels) ImageMagick looks around a pixel while doing the sharpening. It should be a few pixels more than sigma. If it's less, sharpening won't work as expected. If it's more, it will make everything a lot slower with nearly no benefits. Don't overthink it, just choose sigma + 2.
- Sigma : this is the size of the details you want to sharpen, in pixels. This works nearly the same way as the "radius" you find in Photoshop. For sharpening a photo for display, it should be around 0.4-1.0. Do a few tries and pick what you like best.
- Amount : how much sharpening is done. That's the most important setting. Pick something you like.
- Threshold : that's mainly used to avoid sharpening noise. Leave it at 0 unless the sky or other flat areas look too noisy.
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.