You are on page 1of 2

#!

/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

You might also like