Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create contact sheets from CR2 and JPG photos
#!/bin/bash
# Create 7x6 contact sheets
# @jbuchbinder
#
# Dependencies:
# - dcraw
# - imagemagick
SIZE=500
ROWS=6
FONTSIZE=32
DEST=/media/$USER/ARCHIVE/Photos/contact-sheets
#--------------------------------------------------------------------------------------------------------
BATCH=$(( $ROWS * 7 ))
for D in "$@"; do
ITER=0
ls "$D"/*.??? | xargs -n $BATCH | while read X; do
ITER=$(( $ITER + 1 ))
FN=$( basename "$D" )-$( printf '%03d' $ITER ).jpg
if [ ! -f "$DEST/$FN" ]; then
echo "Creating contact sheet $FN"
FILES=""
REMOVELIST=""
for F in $X; do
case $F in
*JPG|*jpg)
FILES="$FILES $F"
;;
*CR2)
BN=$( basename "$F" )
dcraw -e $F
mv ${F//.CR2}.thumb.jpg /tmp/${BN//.CR2}.thumb.jpg
REMOVELIST="$REMOVELIST /tmp/${BN//.CR2}.thumb.jpg"
FILES="$FILES /tmp/${BN//.CR2}.thumb.jpg"
;;
esac
done
montage -verbose -label '%f' -font Ubuntu -pointsize ${FONTSIZE} \
-background '#000000' -fill 'gray' -define jpeg:size=${SIZE}x${SIZE} \
-geometry ${SIZE}x${SIZE}+2+2 -auto-orient $FILES "$DEST/$FN"
echo "Cleaning up"
rm -v $REMOVELIST
else
echo "Skipping existing contact sheet $FN"
fi
done
done
@71m383nd3r

This comment has been minimized.

Copy link

commented Jan 12, 2017

anyway to push it on windows or Mac ?

@jbuchbinder

This comment has been minimized.

Copy link
Owner Author

commented Nov 27, 2017

I could, at least in theory, rewrite it in Go. I just haven't gotten around to doing it; probably a case of "it works well enough for me".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.