Add apng2webp
This commit is contained in:
parent
8c017c5979
commit
e74efe64d6
11
.config/zsh/completions/_apng2webp
Normal file
11
.config/zsh/completions/_apng2webp
Normal file
@ -0,0 +1,11 @@
|
||||
#compdef apng2webp
|
||||
|
||||
_arguments '-h[short help text]' \
|
||||
'--help[short help text]' \
|
||||
'--delay[override milliseconds per frame]:milliseconds' \
|
||||
'1:input file:_files' \
|
||||
'2:output file:_files'
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# End:
|
50
.config/zsh/functions/apng2webp
Executable file
50
.config/zsh/functions/apng2webp
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env zsh
|
||||
# Convert animated PNG to animated WebP. Maximum compression no blend.
|
||||
|
||||
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
||||
|
||||
zmodload zsh/zutil
|
||||
local -a o_help=()
|
||||
local -a o_delay=()
|
||||
zparseopts -D -K -- h=o_help -help=o_help -delay:=o_delay
|
||||
if [[ ${#o_help} -ne 0 || ! -v 2 ]]; then
|
||||
local ret=$(( ${#o_help} ^ 1 ))
|
||||
print -u $(( 1 + ${ret} )) \
|
||||
"usage: ${0} [-h|--help] [--delay MILLISECONDS]" \
|
||||
"<INPUT FILE> <OUTPUT FILE>"
|
||||
return ${ret}
|
||||
fi
|
||||
local input="$(realpath "${1}")"
|
||||
local output="$(realpath "${2}")"
|
||||
|
||||
local tmpdir=$(mktemp --directory --suffix='.apng2webp')
|
||||
pushd ${tmpdir}
|
||||
|
||||
mkdir -p apngdis
|
||||
pushd apngdis
|
||||
cp "${input}" "input.png"
|
||||
apngdis "input.png"
|
||||
popd
|
||||
|
||||
counter=1
|
||||
for file in apngdis/apngframe*.png; do
|
||||
cwebp -lossless -q 100 "${file}" -o "$(printf "%02d" ${counter}).webp"
|
||||
counter=$(( counter+1 ))
|
||||
done
|
||||
|
||||
local -a webpmux_options=()
|
||||
local counter=1
|
||||
for file in apngdis/apngframe*.txt; do
|
||||
local delay=$(grep -Po '=\d+/' "${file}")
|
||||
delay=${delay:1:-1}
|
||||
[[ ${#o_delay} -eq 2 ]] && delay=${o_delay[2]}
|
||||
|
||||
webpmux_options+=(-frame $(printf "%02d" ${counter}).webp +${delay}+0+0+0-b)
|
||||
counter=$((counter+1))
|
||||
done
|
||||
|
||||
# shellcheck disable=2086
|
||||
webpmux ${webpmux_options} -o "${output}"
|
||||
|
||||
popd
|
||||
rm -r ${tmpdir}
|
Loading…
x
Reference in New Issue
Block a user