I was looking for a way to add captions to JPEG images without re-encoding them. It turns out there’s a patch to jpegtran that overlay one JPEG image over another one, without re-encoding either. Here’s how I built it:
Download the sources of the IJG version of jpegtran (I used version 8c), and decompress it somewhere
Download the “drop” patch, and copy the source files into the source extracted in the previous step
configure, make (as usual)
I made a script that automatically adds a label using Imagemagick to create the label, and this version of jpegtran to put them together:
#!/bin/sh JPEGTRAN="/opt/jpeg-8c/bin/jpegtran" if [ $# -lt 3 ] ; then echo "Usage: jpeglabel [label] [in] [out]" >2 exit 2 fi LABELFILE=`mktemp` convert -type truecolor -size 256x16 "label:$1" jpg:"$LABELFILE" "$JPEGTRAN" -drop +16-16 "$LABELFILE" -outfile "$3" "$2" rm "$LABELFILE"
I tried making some examples to show, but it turns out the (experimental) “drop” patch is very fussy about the files you give it. I got it to work on 320x240 pictures from my camera, but not on some other images I tried. It requires the “sampling ratio” to be the same on both images, which is found in the advanced JPEG settings in Gimp.