====== 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 {{tag>util jpeg exif rename files bash}} ~~LINKBACK~~