add --reverse option to animoji-command

This commit is contained in:
tastytea 2022-10-03 15:30:34 +02:00
parent 1fb4dc1de9
commit 76b3451d91
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 21 additions and 3 deletions

View File

@ -4,6 +4,7 @@ _arguments '-h[short help text]' \
'--help[short help text]' \ '--help[short help text]' \
'--delay[milliseconds to show each frame]:milliseconds' \ '--delay[milliseconds to show each frame]:milliseconds' \
'--blend[enable blending (only WebP)]' \ '--blend[enable blending (only WebP)]' \
'--reverse[append all images again, in reverse]' \
'*:input files:_files' '*:input files:_files'
# Local Variables: # Local Variables:

View File

@ -7,18 +7,21 @@ zmodload zsh/zutil
local -a o_help=() local -a o_help=()
local -a o_delay=() local -a o_delay=()
local -a o_blend=() local -a o_blend=()
zparseopts -D -K -- h=o_help -help=o_help -delay:=o_delay -blend=o_blend local -a o_reverse=()
zparseopts -D -K -- h=o_help -help=o_help \
-delay:=o_delay -blend=o_blend -reverse=o_reverse
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
local ret=$(( ${#o_help} ^ 1 )) local ret=$(( ${#o_help} ^ 1 ))
print -u $(( 1 + ${ret} )) \ print -u $(( 1 + ${ret} )) \
"usage: ${0} [-h|--help] [--delay MILLISECONDS] [--blend]" "<FILES>" "usage: ${0} [-h|--help] [--delay MILLISECONDS] [--blend] [--reverse]" \
"<FILES>"
return ${ret} return ${ret}
fi fi
local delay=100 local delay=100
[[ ${#o_delay} -eq 2 ]] && delay=${o_delay[2]} [[ ${#o_delay} -eq 2 ]] && delay=${o_delay[2]}
local blend="-b" local blend="-b"
[[ ${#o_help} -ne 0 ]] && blend="+b" [[ ${#o_blend} -ne 0 ]] && blend="+b"
local -a cmd local -a cmd
if [[ ${1##*.} == "webp" ]]; then if [[ ${1##*.} == "webp" ]]; then
@ -26,11 +29,25 @@ if [[ ${1##*.} == "webp" ]]; then
for file in ${@}; do for file in ${@}; do
cmd+=(-frame ${file} +${delay}+0+0+0${blend}) cmd+=(-frame ${file} +${delay}+0+0+0${blend})
done done
if [[ ${#o_reverse} -ne 0 ]]; then
cmd[-1]=+$((${delay} * 2))+0+0+0${blend}
cmd[6]=+$((${delay} * 2))+0+0+0${blend}
for file in ${(Oa)@:2:-1}; do
cmd+=(-frame ${file} +${delay}+0+0+0${blend})
done
fi
elif [[ ${1##*.} == "png" ]]; then elif [[ ${1##*.} == "png" ]]; then
cmd=(apngasm --output output.png) cmd=(apngasm --output output.png)
for file in ${@}; do for file in ${@}; do
cmd+=(${file} ${delay}) cmd+=(${file} ${delay})
done done
if [[ ${#o_reverse} -ne 0 ]]; then
cmd[-1]=$((${delay} * 2))
cmd[5]=$((${delay} * 2))
for file in ${(Oa)@:2:-1}; do
cmd+=(${file} ${delay})
done
fi
else else
print -u 2 "file format not supported" print -u 2 "file format not supported"
return 1 return 1