diff --git a/zsh/funcs/imgaddexif.sh b/zsh/funcs/imgaddexif.sh new file mode 100644 index 0000000..700df4f --- /dev/null +++ b/zsh/funcs/imgaddexif.sh @@ -0,0 +1,74 @@ +function imgaddexif () ( + #set -x + FLAG_DTO=0 + FLAG_DRYRUN=1 + FLAG_OVERWRITE=0 + + function _print_help() { + echo "Add fixed DateTimeOriginal" + echo "" + echo "Usage: imgfn2exif " + echo " : for example *.JPG" + echo " : The following options are available:" + echo " : -dto date time format" + echo " : -d write exif information" + echo " : -o overwrite existing exif information" + } + + function _new_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=${FLAG_DTO} ${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; + ;; + -dto) + shift; + FLAG_DTO=$1 + shift; + ;; + -h) + _print_help + exit 0 + ;; + -o) + FLAG_OVERWRITE=1 + shift; + ;; + *) + break + ;; + esac + done + + if [ $FLAG_DTO -eq 0 ]; then + echo "You need to provide a date time format; see help" + exit 1 + fi + + for f in $@; do + _new_exif $f + done +) diff --git a/zsh/funcs/imgfn2exif.sh b/zsh/funcs/imgfn2exif.sh index 34ecd20..e991c41 100644 --- a/zsh/funcs/imgfn2exif.sh +++ b/zsh/funcs/imgfn2exif.sh @@ -42,6 +42,10 @@ function imgfn2exif () ( FLAG_DRYRUN=0 shift; ;; + -h) + _print_help + exit 0 + ;; -o) FLAG_OVERWRITE=1 shift; diff --git a/zsh/funcs/imgwoexif.sh b/zsh/funcs/imgwoexif.sh new file mode 100644 index 0000000..4a044c4 --- /dev/null +++ b/zsh/funcs/imgwoexif.sh @@ -0,0 +1,13 @@ +function imgwoexif () ( + function _has_exif () { + file=$1 + current_exif=$(exiftool -DateTimeOriginal ${file}) + if [ -z $current_exif ]; then + echo "Exif DateTimeOriginal not found for ${file}" + fi + } + + for f in $@; do + _has_exif ${f} + done +)