Today I had a pile of photos I wanted to print out. Since I have access to a duplex colour printer I thought it would be neat to print out the EXIF information (datestamp, exposure information, camera model etc) on the back of each picture, and proceeded to knock up the following shell script to do so:
#!/bin/sh
# requires exiftool from
http://www.sno.phy.queensu.ca/~phil/exiftool/# jpeg2ps from
http://www.pdflib.com/download/free-software/jpeg2ps/# a2ps and Ghostscript
function filetopdf () {
jpeg2ps -p a4 -a -b -q $1 > $TMPDIR/img.$3.ps 2> /dev/null
exiftool $1 | a2ps -o $TMPDIR/exif.$3.ps --landscape -B --columns=2 --font-size=7 2> /dev/null
OUTPUTS="$OUTPUTS $TMPDIR/img.$3.ps $TMPDIR/exif.$3.ps"
export OUTPUTS
}
TMPDIR=/tmp
OUTPUTS=""
if [ -d $1 ]
then
COUNT=1
for file in $1/*.jpg ;do
filetopdf $file $2 $COUNT
COUNT=`expr $COUNT + 1`
done
else
filetopdf $1 $2 1
fi
gs -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dDownsampleColorImages=false -dPDFSETTINGS=/prepress \
-sOutputFile=$2 $OUTPUTS
rm $OUTPUTS
Syntax is:
print-pic-with-exif
If supplied with a JPEG file it'll produce a two-page PDF with that one image and the EXIF info nicely formatted on the back. If supplied with a directory it'll do the same job for all the .jpg files inside and concatenate them into a single PDF. Adjust the 'for' loop if your JPEG files are called .jpeg or .JPG or something. EXIF formatting is designed to fit on a sheet of A4 for the output of my camera - if your camera produces more or fewer EXIF tags you may have to rescale the output by adjusting the options to a2ps.
It was a bit tricky because by default Ghostscript insists on compressing the JPEGs down to a much lower resolution. I think I've fixed that, but I'm not sure if Ghostscript is still tinkering with the JPEGs - ideally they should be passed through and embedded directly into the PDF file. Note you'll need as much space in your temp directory as the images take up (the first version avoided this since it concatenated each file in turn to the PDF, but was very much slower).
It all works quite neatly, and the resulting PDF file has photos always oriented the right way - ie if they're landscape they'll stay landscape. It'll depend on the printer driver to rotate landscape pages to portrait if the printer needs them that way.