I have been trying for days to write a script that creates a simple proof sheet from a directory of images. The only scripts I found label the images, which I don't like. I wanted to annotate them as per Labeling on top of the Image itself....

I was unable to use annotate rather than label with montage and could find no examples online. That would be ideal. If someone knows how to implement that, I would prefer it.

What I did so far is to first resize and annotate the images into a separate directory and then create the proof sheet using montage. That works but has the disadvantage of making lossy copies of lossy copies and requiring writing files to a directory.

I tried to pipe the output of the convert for loop to montage but didn't succeed. That would be the second best solution. If anyone knows how to do that, that would be very helpful.

This works but…:

d="<path to image directory>"
dirname=`basename "$d"`
echo $dirname
parent=`dirname "$d"`
echo $parent
parentdir=`basename "$parent"`
echo $parentdir
cd "$d"
if [ -f "$parentdir-$dirname proof sheet.jpg" ]
then
    rm "$parentdir-$dirname proof sheet.jpg"
fi
tilenum=5
spacing=1
scrw=$((1920-(tilenum*spacing+spacing)))
imgw=$(($scrw/$tilenum))
echo $imgw
if [ ! -d rszannot ]
then
    mkdir rszannot
else
    rm rszannot/*
fi
shopt -s nullglob # prevents errors for extensions not found
shopt -s nocaseglob # case insensitive args
for f in "${arg}"*.{jpg,jpeg,png,gif}
do
    fn=$(basename "${f%.*}")
    convert -verbose "$f" \
    -define jpeg:size=${imgw}x \
    -quality 100 \
    -resize ${imgw}x \
    -gravity south \
    -pointsize 20 \
    -stroke '#000C' -strokewidth 2 -annotate 0 '%f' \
    -stroke  none   -fill white    -annotate 0 '%f' \
    "rszannot/$fn-${imgw}x.jpg"
done
cd rszannot
montage -verbose \
-quality 100 \
-background black \
-geometry +${spacing}+${spacing} \
-tile ${tilenum}x \
*.jpg \
"../$parentdir-$dirname proof sheet.jpg"
open "../$parentdir-$dirname proof sheet.jpg"
shopt -u nocaseglob
shopt -u nullglob

proof sheet

1

There are 1 answers

13
fmw42 On

You can resize and annotate all your images in a sub shell and save to miff:, then pipe that to montage in Unix Imagemagick. Here is an example:

list="lena.jpg barn.jpg mandril3.jpg monet2.jpg zelda1.jpg redhat.jpg"
( 
for img in $list; do
echo >&2 "$img"
convert $img -resize "100x100^" -extent 100x100 \
-font helvetica -pointsize 14 -fill white \
-gravity south -annotate +0+5 "%f" \
miff:-
done
) | montage - -tile 3x2 -geometry +0+0 result.png

enter image description here