BatchImageProcessingHowAndWhy: I'll try again. I wrote this earlier today, and the browser ate it; that's what I get for using the latest development version of Opera, I guess. Ah well.

I’ll try again. I wrote this earlier today, and the browser ate it; that’s what I get for using the latest development version of Opera, I guess. Ah well.

I want to be able to take a load of images and do the same things to all of them. The what might differ greatly, depending on my mood, the lighting, the camera used and the type of shots; if it’s street photography, I might want the images to all be a little darker, add some noise then convert to monochrome. If it’s landscapes I may want auto-levels, unsharp mask then a touch of glow. It’s different, every time. I like to treat each folder of images as a project in their own right, pulling out one or two shots for special treatment, then giving the rest the rest a consistent style. To my mind at least, it strengthens the whole look.

But the how. Ah. There’s the thing.

If there’s one thing I hate about Photoshop, it’s that way that Batch Processing is so badly broken. What’s more annoying, it’s broken due to the absence of one single, solitary checkbox.

Theoretically, it’s perfect. You can record an Action, then set it to run those instructions across a whole shedload of images, and you’re done.

But.

If you’re working in jpeg (as your end result is likely to be), you’ll get a dialog box appearing for every single shot asking to confirm the compression ratio when you save. Batch mode ain’t batch mode if you have to sit there like a lemon (do lemons sit?) hitting OK a hundred times. That’ not Batch Mode. That’s torture, dammit. Just one checkbox with the words “Set as default” beside it, and Photoshop’s Batch Mode would go from utterly useless to perfect, in a second. It’s that simple. Really.

Over in the world of Linux where the grass is always greener, there’s the GIMP. This has a super-powerful Batch Mode where you can write entire scripts to control absolutely everything, and GIMP will cheerfully chew through a folderful of images applying the script to each one. The problem here is that it’s just too powerful. I want simplicity, not power in this case. GIMP scripting isn’t my idea of quick-and-easy, at all.

So we’re on to Imagemagick. This is a set of command-line tools for manipulating images. It’s every bit as powerful as Photoshop or GIMP, but takes a lot of trial and error to master. Working in Imagemagick is a little like piloting a submarine; you can’t see where you’re going but you’ve a lot of power to help you get there! It’s well worth the effort to learn though, and is a great tool for the Linux-using photographer.

One of the things I wanted to be able to do was apply a lomo-like effect to a folder full of images. This would give the shots a characteristic vignette and boost the overall saturation; it’s a lovely retro style that’s more popular now than ever before.

I found a script online which roughly did what I needed here. As it stands, the script on that page takes just one image with the name original.jpg and spits out a lomofied image called output.png. I’ve taken that script and set it to use a filename passed from the command line and output a file with the prefix lomo_ added to the filename. I’ve also changed the script so that it will correctly add the vignette to any size of image; the original version only handled files 800×600 in dimension.

Here’s my revised script:

 #!/bin/bash
 convert  -size `identify -format "%wx%h" $1` xc: \
  -fx '(1-(2*i/w-1)^4)*(1-(2*j/h-1)^4)' \
  lomo_mask.png
 convert -contrast -modulate 100,120 $1 lomo_$1
 composite -compose Multiply lomo_mask.png lomo_$1 lomo_$1

Copy and paste that into a file called lomo.sh then type:

 chmod +x lomo.sh

Copy that file (as root) to /usr/local/bin so it can be run from anywhere on your computer. Test it with lomo.sh myfile.jpg and you should end up with a shot called lomo_myfile.jpg as a result.

If all went well, you should be able to use lomo.sh on an entire folder full of images like this:

 for i in *.jpg; do echo $i; lomo.sh $i; done

This will take each shot, display the filename then apply lomo.sh to it, kicking out a new lomoized jpeg file then working on the next file in turn. Job done.

It’s well worth learning how to use Imagemagick and putting it to use for your batch-processing needs. I’m going to be creating my own scripts, and I’ll share them with you over the coming months.

Like this post? Why not buy me a coffee? Thank you.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.