#!/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=(-f 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]})]" \ " …" 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", "Subject"}' for file in ${@}; do newfile=photoprep/${file##*/} newfile=${newfile%.*}.${format} local exif_json=$(mktemp --suffix='.photoprep.json') # write select EXIF data to temporary file exiftool -json ${file} | jq ${jq_filter} | grep -v null > ${exif_json} magick -quality ${quality} ${file} -auto-orient -strip -resize ${size} ${newfile} # add EXIF data to new (scrubbed) file exiftool -json=${exif_json} -quiet -overwrite_original ${newfile} rm ${exif_json} print -n '.' done print