5
Mar

Using exiftool to Create List of Pictures Matching a Keyword/Tag


JPEG Photos with EXIF data, the topic of this post

The exiftool utility is an indispensable tool in the arsenal of picture organization tools and can save you a ton of time when used properly. There are a TON of uses documented in its manual, but there are even more uses outside of that. You just need to be clever. Take the following shell script for example…

This script will call exiftool from the command line or terminal to search through a directory of photos, pick out the ones that match a particular keyword or tag (certainly not limited to these, it can be any attribute stored in exif data), and then save them to a file. The 2> /dev/null portion simply throws away any messages exiftool creates and only leaves you with the goodies in the $RESULT_FILE. Not only does it find the photos that you want with the “favorites” keyword, it also adds the path so you can use the terminal to open them, sort them, or copy them to another location.

#!/bin/sh

PICS_DIR=/home/username/pictures
KEYWORD=favorites
RESULT_FILE=favorite_photos.txt

echo -n "Now, grab all of your photos tagged with "$KEYWORD" in $PICS_DIR..."
(
   exiftool -ext .JPG -fast -p 'source$directory/$filename;destination$directory/$filename; 
   $Keywords' -qq -r -m "$PICS_DIR" | grep -i "$KEYWORD" > $RESULT_FILE
) 2> /dev/null
echo " done"

I have taken this one step further to develop this script (which I’ve appropriately named “picup”) that automatically uploads photos marked with “favorites” to an online gallery powered by ZenPhoto. Pretty clever if I do say so myself.

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 5 Comments So Far

  • boo
    March 29th, 2010 at 8:56 am

    Thanks. If the output file is empty the tag was not found.
    Make sure your images actually have tags. In my case, digiKam does not write the tags to the image file but rather stores that information in a database. This can be corrected in configuration and subsequently using the “write metadata to each file” command from the metadata panel’s “more” dropdown at the bottom.

  • [email protected]
    March 29th, 2010 at 10:13 am

    I suppose you could add in your script an if…then statement that checks if the file is empty:

    [bash]
    if [ -s $FILE ] ; then
    echo "$FILE has data."
    else
    echo "$FILE is empty."
    fi
    [/bash]

  • David Ker
    August 21st, 2010 at 9:09 am

    Derek, I’ve been working on a similar project and wonder if you could help me. The details are here: https://sites.google.com/site/kanyimbe/ubiqivo.

    Basically the idea is that I want a platform independent way to create an index.htm file containing a list of all the files in a directory with their metadata. A friend made this work with perl but I believe that won’t work for everyone.

    Do you have any idea how we might make this happen?

    Many thanks,

    David

  • [email protected]
    August 30th, 2010 at 7:41 am

    If it’s cross platform compatibility you’re after, I suppose programming it in Java would be fairly attractive solution. But, there are some folks that claim perl is a completely legitimate cross platform programming language…
    http://techrepublic.com.com/5208-11195-0.html?forumID=87&threadID=194492&start=0&tag=content;leftCol

Who Linked To This Post?

  1. digiKam, Gwenview, and tagging - openSUSE Forums

Share your thoughts, leave a comment!