From ad9ca238b64d3050384ec60a0ceff7ff5546b28d Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 23 May 2023 14:42:22 +0200 Subject: [PATCH] zah: add pjotoprep --- .config/zsh/functions/photoprep | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 .config/zsh/functions/photoprep diff --git a/.config/zsh/functions/photoprep b/.config/zsh/functions/photoprep new file mode 100755 index 0000000..ee4e9b3 --- /dev/null +++ b/.config/zsh/functions/photoprep @@ -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]})]" \ + " …" + 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