1
0
Fork 0
dotfiles/.config/zsh/functions/animoji-command

60 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env zsh
# Output commands to generate animated images from files
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
zmodload zsh/zutil
local -a o_help=()
local -a o_delay=()
local -a 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
local ret=$(( ${#o_help} ^ 1 ))
print -u $(( 1 + ${ret} )) \
"usage: ${0} [-h|--help] [--delay MILLISECONDS] [--blend] [--reverse]" \
"<FILES>"
return ${ret}
fi
local delay=100
[[ ${#o_delay} -eq 2 ]] && delay=${o_delay[2]}
local blend="-b"
[[ ${#o_blend} -ne 0 ]] && blend="+b"
local -a cmd
if [[ ${1##*.} == "webp" ]]; then
cmd=(webpmux -o output.webp)
for file in ${@}; do
cmd+=(-frame ${file} +${delay}+0+0+0${blend})
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
cmd=(apngasm --output output.png)
for file in ${@}; do
cmd+=(${file} ${delay})
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
print -u 2 "file format not supported"
return 1
fi
if [[ -o INTERACTIVE ]]; then
print -z "" ${cmd}
else
print "" ${cmd}
fi