Fun things to do with computers and photographs
Random header image... Refresh for more!

An introduction to photohack

photohack is a (Unix) shell script that makes it quick to perform batch processing of photographs and other images, in particular for RAW images. I would much rather be out shooting than sitting at the computer processing images, so I decided to spend the time to write a shell script wrapper around free programs such as dcraw and ImageMagick. I offer it here for your use if you wish, with NO WARRANTEE OF ANY KIND.

Since photohack is a shell script, you have to operate it by typing in a shell (‘command line’). There is no GUI (graphical user interface) at all—you use other image previewing programs to see what photohack produces. Note also that since photohack is a shell script, it is a power tool—used carelessly, you can cause a lot of damage.

So it’s not for everyone then. On with the introduction.

Features

The original purpose of photohack was to mechanize and simplify the more tedious parts of post-processing for digital photography images. Over time, I have added features, to the point where now, most of my images for web use are produced without use of a graphical image processing program.

photohack is, however, designed to work well with other image editing programs for those times when you do need to use them.

The features of photohack that help with reducing tedious post-processing work include:

  • Renaming and renumbering images
  • Generating “proof” images in web size
  • Culling and selection of images
  • Sensible and quick RAW conversion (using dcraw)
  • Generation of multiple image crops
  • Generation of borders and watermarks
  • Generation of a range of different output sizes

Finally, since photohack relies on the file system for storing all its information, it also plays nicely with any backup program.

Limitations

photohack lacks some refinements (what shell script doesn’t!). To save you disappointment later, here are some of them:

  • It has no graphical user interface
  • Error messages, if any, can be a little cryptic
  • It insists on naming your directories and files in a certain way
  • It will sometimes silently ignore your input if it didn’t understand it
  • If you provide it with wrong instructions, it might also do what you literally asked it to do, with no apology and no “undo”
  • It has bugs

Overview of Usage

This section provides an overview of how photohack is used. The intention here is to allow you to understand the overall way it works. See the other tutorial for more detailed information on how to do certain things.

Initializing an album

photohack wants directories and files to be named and structured in a certain way. That ‘way’ is the way that I decided when I wrote the program, and it can’t be changed at present (sorry).

I organize my images by year—a directory for each year, and then individual directories for each shoot or outing. These I call “albums.” Each album has to have a name that has the form:

0908a Some more text

That is, four digits, a letter, a space, and then whatever you want. By convention, I use the first two digits for the year and the second for the month, but you can number the album however you like (as long as i has four digits).

Within each album, photohack creates the following directory structure, which it uses to manage and manipulate images:

Cache
Camera
  Download
  Images
  Raw
  Proof
Data
Generated
  Index
  Print
  Web
  ...
Wastebin
Workspace

Importing images

To import images from a shoot, just drop them into the Camera/Download directory. Then type:

$ photohack album import

photohack will renumber the images and move them into the Camera/Raw or Camera/Images directory. It will also generate titled proof images in the Camera/Proof directory.

Selecting images

Open up images in the Camera/Proof directory and view them using whatever image viewer you have handy (I use the Preview program that comes with Mac OS/X). Images that you want to add to the working set, you “tag” like so:

$ photohack tag 7 12-16 24 +selected

(Note that you can use whatever tags you like — this is just an example.)

Generating images

photohack allows you to generate output images in vast range of (configurable) output formats. For example, to generate all images tagged “selected” in web output size, you would type:

$ photohack write @web selected

To generate image 7 at 300dpi for printing on 5×7″ paper (with the image cropped to fit):

$ photohack write 7 [7:5] @5x7

To generate an “index” image, which shows the image, RGB histograms, and other information, for all images tagged “selected”:

$ photohack write selected

(Index images are more useful than proof images once initial selection has been done, as they are generated from the RAW file instead of the low-res JPG provided by the camera, and they have your image processing adjustments made to them.)

RAW conversion

photohack uses the dcraw program to convert RAW files. You can customize the way it processes RAW files on a per-album or per-image basis. For example, if image 12 has clipping highlights, you can recover them (to some degree) with:

$ photohack options 12 highlight=blend

You can adjust exposure during RAW processing:

$ photohack options 17 exposure=-0.3

And a bunch of other stuff: noise reduction, chromatic aberration correction, white balance, distortion correction. After changing the RAW options for these images, you may want to re-generate various versions. For example, to check the histograms of the above two images:

$ photohack index 12 17

Adjusting images

You can set additional options to process images. These are executed using the comprehensive ImageMagick image processing suite. For example, to increase the contrast of image 14, increase red tones slightly, and reduce saturation:

$ photohack options 14 contrast+30 red+5 saturation-5

Borders and titling

photohack makes it easy to generate borders and titles on images. For example, to generate a web-sized version of image 12 with the title “My Great Photograph” we do:

$ photohack title 12 My Great Photograph
$ photohack write 12 @titled

Different styles for the border and title text can be defined, although less simply. (Bordering and titling works well on web-sized images only for now, as dimensions are specified in absolute pixels.)

Working with external programs

photohack accepts its limitations, and provides a way to easily use external image editing programs within its framework. The overall workflow is:

  1. photohack: Import, number, RAW conversion, whole-image adjustments
  2. external program: perform any image manipulation you like
  3. photohack: Generate output images in different sizes and crops

Practical Implications

Like any tool, photohack takes some time to learn. Since it’s a command-line tool, you will need to be reasonably fast at typing as well.

Once learnt, though, I have found that I am a lot faster than before to get to useful results after returning home from a photographic outing. Once I’ve decided on a number of images, and worked on the image adjustments and cropping, it’s basically done. I generate web-sized images for upload, and larger images with border and title for client preview (if I’m lucky enough to have one). I might also generate a few variants in black and white – this takes a few extra seconds per image.

I can easily come back to images later on, review the index image, tweak the adjustments, and regenerate them in various sizes. And I like that I can do that without having to tie up huge amounts of extra storage needed for PhotoShop (or whatever) files. I only need to keep the RAW files, and a few bytes of metadata per image.