From 2dfb3240cb4cda573b12a5c8845d717ba495d134 Mon Sep 17 00:00:00 2001 From: Marcel Schoengens Date: Mon, 1 May 2023 13:45:22 +0200 Subject: [PATCH] Add new command to manage images / media --- zsh/funcs/imgfn2exif.sh | 58 +++++++++++++++++++++++++++++++++++++++++ zsh/zshrc | 2 ++ 2 files changed, 60 insertions(+) create mode 100644 zsh/funcs/imgfn2exif.sh diff --git a/zsh/funcs/imgfn2exif.sh b/zsh/funcs/imgfn2exif.sh new file mode 100644 index 0000000..34ecd20 --- /dev/null +++ b/zsh/funcs/imgfn2exif.sh @@ -0,0 +1,58 @@ +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 " + echo " : for example *.JPG" + echo " : 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 +) diff --git a/zsh/zshrc b/zsh/zshrc index e04c5d7..85317bb 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -126,6 +126,8 @@ source $DOTCONFDIR/dotconf.sh ### Shell function definition +source $DOTCONFDIR/zsh/funcs/*.sh + function _sortimages () { SOURCE="$1" TARGET_PREFIX="$2"