LinuxPhoto.org

The place for all photography and linux fans

COMMAND LINE BATCH PROCESSING

by Jacek Góźdź

    What is needed?

    All linux distributions have a shell (here I use BASH) and SED, so you need to download and compile DCRaw ()for decoding RAW files and a command line tools for editing bitmaps (I use ImageMagick but there are many more, just check the software section of my website).
     
    Now create and open a new file. It should be executable (therefore remember about permissions). All you need to write now is a simple script.

    The script

    Below I present a "blank" script with place for all the commands you need.

    #! /bin/bash
    for i in *.png; do j=`echo $i | sed -e 's/\.png/\.jpg/'`; \

     

    your code here


     
    done;

    A little explanation. First line shows where to look for bash, last line simply ends the loop, don't worry about both of them. The second line reads all the filenames that ends with .png and add .jpg to the created files. One needs to edit those if different file types are to be processed. Then replace "your code here" with commands you want to be executed on every processed image using $i as a name of original file and $j as the name of output file. Remember that all of the images that are in current directory and ends with .png will be processed. this script do not work if the filename has spaces!

    Example 1

    Lets create jpeg thumbnails from TIFF files. Those thumbnail should be about 300x200 points and 80% quality. The problem is that there are horizontal and vertical images. To handle with that simply ask to create 300x300 images and everything will be OK as ImageMagick will make the longer dimension 300 pixels, and keep aspect ratio of original image.

    #! /bin/bash
    for i in *.tif; do j=`echo $i | sed -e 's/\.tif/\.jpg/'`; \
      convert -resize 300x300 -quality 80% $i $j;
    done;

    Example 2

    Lets add 3 pixels thick black border and then big white border around TIFF files. Then add my signature (different image, in this case a signature.png) at the lower-right corner. The final image will be also TIFF (the same size and quality) but with "-border" added to its name.

    #! /bin/bash
    for i in *.tif; do j=`echo $i | sed -e 's/\.tif/\-border.tif/'`;
      convert -bordercolor black -border 3x3 -bordercolor white -border 180x200 $i $j;
      composite -dissolve 50% -geometry +250+210 -gravity southeast signature.png $j $j;
    done;

    Example 3

    Lets develop Minolta RAW files (.mrw) with dcraw (-T makes it write into a TIFF file, put other options if needed), and create their sharpened and downsized (to 25% of original size) thumbnails. In the end delete all .tiff files (remember - ALL TIFF FILES that will be in the current folder).

    #! /bin/bash
    dcraw -T *.mrw
    for i in *.tiff; do j=`echo $i | sed -e 's/\.tiff/\.jpg/'`;
      convert -resize 25% -quality 90% -sharpen 1x10 $i $j;
    done;
    rm *.tiff


 

Copyright 2007, Jacek Góźdź
template by : David Herreman