Files
dotconfigs/zsh/funcs/imgfn2exif.sh
T

59 lines
1.6 KiB
Bash

function imgfn2exif () (
#set -x
FLAG_DRYRUN=1
FLAG_OVERWRITE=0
function _print_help() {
echo "Use filename to get DateTime from image and add as DateTimeOriginal Exif information"
echo ""
echo "Usage: imgfn2exif <options> <file-selection>"
echo " <file-selection> : for example *.JPG"
echo " <options> : The following options are available:"
echo " : -d write exif information"
echo " : -o overwrite existing exif information"
}
function _img_fn_2_exif () {
file=$1
file_name=$(basename ${file})
file_name_prefix=${file_name%.*}
if [ $FLAG_DRYRUN -eq 1 ]; then
cmd=(echo)
else
cmd=()
fi
cmd+=(exiftool -overwrite_original -DateTimeOriginal=${file_name_prefix} ${file})
if [ $FLAG_OVERWRITE -eq 0 ]; then
current_exif=$(exiftool -DateTimeOriginal ${file})
if [ ! -z $current_exif ]; then
echo "Exif DateTimeOriginal already exists for ${file}: ${current_exif#*: }"
return
fi
fi
echo Executing: ${cmd}
"${cmd[@]}"
}
while true; do
case $1 in
-d)
FLAG_DRYRUN=0
shift;
;;
-o)
FLAG_OVERWRITE=1
shift;
;;
*)
break
;;
esac
done
for f in $@; do
_img_fn_2_exif $f
done
)