#!/bin/bash # Usage: # dcraw-thumbnailer [size] [source] [destination] # Exit with error on any error set -e size=$1 source=`echo "$2" | sed 's/file:\/\///'` destination=$3 # Conversion table from EXIF orientation code to degrees (Bash 4 and newer) declare -A conv=( ["1"]="0" ["3"]="180" ["6"]="90" ["8"]="270" ) # Read orientation with exiftool # Triple -s : output only the value # -n : output numerical value, do not convert to human readable form rotation_code=`exiftool -Orientation -s -s -s -n "$source"` rotation_deg="${conv[$rotation_code]}" # Extract the thumbnail (usually stored as JPEG) with dcraw, resize, rotate and convert it. # The target format will be inferred from the destination file name (usually PNG). dcraw -c -e -w "$source" | convert -resize ${size}x${size} -rotate "${rotation_deg}" - "$destination"