1
0
Fork 0
dotfiles/.config/zsh/functions/photoprep

38 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env zsh
# prepare photos for sharing them online
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
zmodload zsh/zutil
local -a o_quality=(-q 90)
local -a o_size=(-s 1500x1500)
local -a o_format=(-s webp)
local -a o_help=()
zparseopts -D -K -- q:=o_quality s:=o_size f:=o_format h=o_help
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
local ret=$(( ${#o_help} ^ 1 ))
print -u $(( 1 + ${ret} )) "usage: ${0} [-h]" \
"[-q QUALITY (=${o_quality[2]})]" \
"[-s SIZE (=${o_size[2]})]" \
"[-f FORMAT (=${o_format[2]})]" \
"<FILE> …"
return ${ret}
fi
local quality=${o_quality[2]}
local size=${o_size[2]}
local format=${o_format[2]}
mkdir -p photoprep
local jq_filter='.[0] | {"ImageDescription", "UserComment", "Comment", "Description", "Description-en-US", "Description-de-DE"}'
for file in ${@}; do
newfile=photoprep/${file##*/}
newfile=${newfile%.*}.${format}
local exif_json=$(mktemp --suffix='.photoprep.json')
exiftool -json ${file} | jq ${jq_filter} | grep -v null > ${exif_json}
magick -quality ${quality} ${file} -auto-orient -strip -resize ${size} ${newfile}
exiftool -json=${exif_json} -quiet -overwrite_original ${newfile}
rm ${exif_json}
print -n '.'
done
print