Sync JPEG comments and EXIF comments of image files

I'm planning to keep image related comments in my digital camera images. Unfortunately there are two ways to attach information to jpegs and there are tools that use one or the other but not both. So I've created the following script that syncs those two kinds of comments and handles conflicts gracefully.

#!/bin/bash
 
dir=$1
dir=${dir:=`pwd`}
 
echo "::: Equalizing JPEG comments and EXIF comments in $dir"
 
prompt() {
 
    while true; do
 
        read -p "which takes precedence [E]xif, [J]peg (or [C]ancel)? " -n1 answer
        echo ""
 
        case $answer in
            [eE]) break;;
            [jJ]) break;;
            [cC]) exit;;
        esac
 
        echo "please aswer: e/j/c"
 
    done
 
}
 
jpeg2exif() {
    echo "+ copying jpeg to exif comment"
    exifcom -f -w "$jpegcom" "$file"
}
 
exif2jpeg() {
    echo "+ copying exif to jpeg comment"
    echo "FIXME: unimplemented"
}
 
pushd "$dir" >/dev/null
for file in *.jpg *.jpeg *.JPG *.JPEG; do
 
    if [ ! -f "$file" ]; then continue; fi
 
    echo "+++ file: $dir/$file"
 
    exifcom=`exifcom  "$file"`
 
    jpegcomtmp=`mktemp`
    jhead -cs "$jpegcomtmp" "$file" >/dev/null
    jpegcom=`cat "$jpegcomtmp"`
    rm -f "$jpegcomtmp"
 
    echo "+ jpeg comment: $jpegcom"
    echo "+ exif comment: $exifcom"
 
    if [ "$jpegcom" = "$exifcom" ]; then
        echo "! fields are equal - skipping"
        continue;
    fi
 
    if [ ! -z "$jpegcom" -a -z "$exifcom" ]; then
        jpeg2exif
        continue
    fi
 
    if [ -z "$jpegcom" -a ! -z "$exifcom" ]; then
        exif2jpeg
        continue
    fi
 
    if [ ! -z "$jpegcom" -a ! -z "$exifcom" ]; then
        echo "! both fields hold a comment"
        prompt
        case $answer in
            [eE]) exif2jpeg;;
            [jJ]) jpeg2exif;;
        esac
        continue
    fi
 
done
popd >/dev/null

Linkbacks

Use the following URL for manually sending trackbacks: http://rigo.info/lib/plugins/linkback/exe/trackback.php/en:blog:sync_jpeg_comments_and_exif_comments_of_image_files
en/blog/sync_jpeg_comments_and_exif_comments_of_image_files.txt · Utolsó módosítás: 2009-04-14 00:00 (külső szerkesztés)
CC Attribution-Noncommercial-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0