Script for batch resizing of Canon *.CR2 files to JPG

Discussion in 'Digital Photography' started by bizcotti, Dec 11, 2009.

  1. bizcotti

    bizcotti Guest

    I just put together a wrapper batch script that helps me batch
    process
    the raw images from my Canon G10 while preserving EXIF data and file
    timestamps. It runs on Linux (Ubuntu system).

    If there is any interest for a GUI I can create that as well, but I
    prefer the command line.

    Requirements:
    dcraw
    convert (ImageMagick)
    exiftool (perl)
    bash shell

    ===========================8X=================
    #!/bin/bash

    # cr2cnv
    # Allan Peda <allan.peda at gmail.com>
    # wrapper script to convert Canon CR2 files to jpeg
    # Includes scaling and EXIF data

    # default scaling value (percent)
    declare -i SCALE=15
    function show_help {
    prog=$(basename $0)
    echo "Usage:"
    echo " $prog -s n IMG_XXX.CR2"
    echo " Where n is between 1 and 100."
    echo " Default n = ${SCALE}%."
    }

    if [ $# -eq 0 ]
    then
    show_help
    exit
    fi

    stdout="-c"
    bal_calc="-a"
    bal_camera="-w"
    interp_vng="-q 1"
    interp_ppg="-q 2"
    interp_ahd="-q 3"

    DCRAW="/usr/local/bin/dcraw"
    TMPFILE=$(mktemp /tmp/canonXXXXXXX)
    while getopts 's:h' opt; do
    if [ "$opt" == 'h' ]
    then
    show_help
    exit
    fi
    SCALE="${OPTARG}"
    done
    if [ "$SCALE" -lt 1 ] || [ "$SCALE" -gt 100 ]
    then
    echo "Illegal scaling factor ($SCALE)"
    exit
    fi
    while [ $# -gt 0 ]
    do
    f=$1
    if [ -r "$f" ]; then
    t=$(basename "${f%%[cC][rR]2}"jpg)
    $DCRAW $stdout \
    $interp_ahd \
    $bal_camera \
    "$f" > ${TMPFILE}
    # reduce huge images to 10% original size
    convert pgm:${TMPFILE} -resize "${SCALE}%" -quality 95% -
    compress
    JPEG "$t"
    # preserve EXIF data
    exiftool -overwrite_original -TagsFromFile "$f" "$t" >/dev/null
    $DCRAW -z "$t" || touch -r "$f" "$t"
    fi
    shift
    done
    test -f $TMPFILE && rm $TMPFILE
     
    bizcotti, Dec 11, 2009
    #1
    1. Advertisements

  2. bizcotti

    bizcotti Guest

    bizcotti, Dec 11, 2009
    #2
    1. Advertisements

  3. bizcotti

    Robert Coe Guest

    I just put together a wrapper batch script that helps me batch
    : process
    : the raw images from my Canon G10 while preserving EXIF data and file
    : timestamps. It runs on Linux (Ubuntu system).

    Thanks, but we Windows users don't need it. DPP has that batch conversion
    capability built in. ;^)

    Bob
     
    Robert Coe, Dec 12, 2009
    #3
  4. And you can make DPP start, download the images, produce the
    downsized JPEGs, place them in the archive next to the RAWs,
    upload the JPEGs to your personal homepage and send another,
    correctly downsized version to your iphone ... whenever you
    connect the camera or a card containing G10 RAWs?

    In other words, is DPP completely scriptable, or do you have to
    start it by hand and start the batch by hand and add the photos
    to the batch by hand, too?

    -Wolfgang
     
    Wolfgang Weisselberg, Dec 13, 2009
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.