Add Captions with Basic EXIF Data to Photos using ImageMagick

Adding a caption containing basic EXIF info such as aperture, shutter speed, and ISO to a photo can come in useful in many situations. And a simple Bash shell script automates this action. The script uses the ExifTool and ImageMagick tools to extract EXIF data from a specified image. It then adds a caption containing the extracted aperture, shutter speed, and ISO values to the image.

#!/usr/bin/env bash
fnumber=$(exiftool -aperture $1 | cut -d':' -f2)
exposure=$(exiftool -shutterspeed $1 | cut -d':' -f2)
iso=$(exiftool -iso $1 | cut -d':' -f2)
convert $1 -gravity South -background Black \
-font mononoki-Regular -pointsize 50 -fill White \
-splice 0x54 -annotate 0x0 "Aperture:$fnumber Shutter speed:$exposure ISO:$iso"  annotated_$1
xdg-open exif_$1

In this case, the script uses the Mononoki font for the caption, but you can replace it with any other font installed on your system. To list all fonts for use with ImageMagick, run the convert -list fonts command.

Paste the code above into a text file and save it under the exif-to-annotate name. Use then the following commands to install the script and make it executable:

sudo cp exif-to-annotate /usr/local/bin/
sudo chown root:root /usr/local/bin/exif-to-annotate
sudo chmod 755 /usr/local/bin/exif-to-annotate

To add a caption to a photo, run the annotate /path/to/foo.JPG command (replace /path/to/foo.JPG with the actual path and filename of the photo).

Of course, you can tweak the script to fit your specific needs. For example, you can replace the EXIF info with a copyright notice, or modify the script to add an arbitrary text on-the-fly.

This is an excerpt from the Linux Photography book. Get your copy here.

Tech writer covering Linux and open source software

Tagged with: , ,
Posted in Open Source, Scribbles, Software
%d bloggers like this: