1
0
Fork 0

zah: add pjotoprep

This commit is contained in:
tastytea 2023-05-23 14:42:22 +02:00
parent 8911716cc3
commit ad9ca238b6
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
1 changed files with 32 additions and 0 deletions

32
.config/zsh/functions/photoprep Executable file
View File

@ -0,0 +1,32 @@
#!/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
for file in ${@}; do
newfile=photoprep/${file##*/}
newfile=${newfile%.*}.${format}
magick -quality ${quality} ${file} -strip -resize ${size} ${newfile}
print -n '.'
done
print