Skip to content

Instantly share code, notes, and snippets.

@jbuchbinder
Last active November 27, 2017 16:13
Show Gist options
  • Save jbuchbinder/667efd7355f9c2da948a to your computer and use it in GitHub Desktop.
Save jbuchbinder/667efd7355f9c2da948a to your computer and use it in GitHub Desktop.
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
Copy link

anyway to push it on windows or Mac ?

@jbuchbinder
Copy link
Author

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