renaming jpegs based on f-spot tags

f-spot does not have an option for renaming files, so if you want to rename your images you need to export them from f-spot, rename them, then re-import. It sounds a hassle but actually it’s quite easy to streamline, especially since it’s possible just to drag and drop the images you’re interested in. The Drag’n’Drop … Continue reading “renaming jpegs based on f-spot tags”

f-spot does not have an option for renaming files, so if you want to rename your images you need to export them from f-spot, rename them, then re-import. It sounds a hassle but actually it’s quite easy to streamline, especially since it’s possible just to drag and drop the images you’re interested in. The Drag’n’Drop ability also gets around the problem where really long filenames can’t be exported because of their filename length.

I rename my jpegs based on the the tags I’ve created in f-spot. I don’t know how f-spot chooses the order to write the tags to the EXIF fields, and I don’t much care. It’s sufficiently robust for me, and it means I can rapidly locate images by using the ‘locate’ command.

Here’s the script I use:

#!/bin/bash
#
#       Script: rename_fspot_jpegs
#       Notes:  Renames jpegs based on their embedded tags
#               
#               Modify the BASEDIR variable as required
#



scriptname="$(basename $0)"

# modify this section as required for your setup. 
# you should be able to just change the BASEDIR to your own home directory,
# and export your jpegs from f-spot into jpegs_in.
BASEDIR=/home/dougie
INDIR=${BASEDIR}/jpegs_in
OUTDIR=${BASEDIR}/jpegs_out

# Change this to whatever you want to separate the tags in your filenames
TAGSEP="--"

mkdir -p ${OUTDIR} || exit 2
echo "STARTING script: ${scriptname}"

# process jpegs and extract tags
echo "Process file list for renaming ..."
cd ${INDIR} || exit 2

ls | while read fname 
do
# END each filename with datestamp
        echo "Processing ${fname}"
        exif_created=`exiftool -overwrite_original -d %c -CreateDate "${fname}" | sed 's///-/g' | sed 's/^.*: //' | sed 's/:/-/g'`
        if [[ -z ${exif_created} ]] ; then
# Create date not found. Using original
                exif_created=`exiftool -overwrite_original -d %c -DateTimeOriginal "${fname}" | sed 's/^.*: //' | sed 's/:/-/g'`
        fi

#       Copy the contents of Description field into UserComment field.
#       UserComment field often ends up garbled and appears to be used
#       by some gallery sites - e.g. zenfolio.
#
        exif_description=`exiftool -overwrite_original -Description "${fname}" | sed 's/^.*: //'`
        exiftool -overwrite_original -UserComment="$exif_description" "${fname}"
# f-spot writes its tags to the Subject field.

        exif_tags=`exiftool -overwrite_original -Subject "${fname}" | sed 's/^.*: //' | sed "s/,/ ${TAGSEP}/g"`
        echo "Tags: ${exif_tags}"
        if [[ ! -z "${exif_tags}" ]] ; then
                newfname="${exif_tags} ${TAGSEP} ${exif_created}"
        else
                newfname="${exif_created}"
        fi

# we need the --backup=numbered option in case we have duplicate filenames
        cp "${fname}" "${OUTDIR}/${newfname}" --backup=numbered
done

# now we have a directory full of filenames with no .jpg suffix
cd ${OUTDIR} || exit 2
ls | while read fname
do
        mv "${fname}" "${fname}".jpg
done

# EOF: rename_fspot_jpegs

(Visited 14 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.