Skip to content

Instantly share code, notes, and snippets.

@idolpx
Last active December 16, 2023 07:36
Show Gist options
  • Select an option

  • Save idolpx/a0e4fecbaeaaf79f8e9e48b5d622bfa9 to your computer and use it in GitHub Desktop.

Select an option

Save idolpx/a0e4fecbaeaaf79f8e9e48b5d622bfa9 to your computer and use it in GitHub Desktop.
Converts a .WEBP file to animated .GIF
#!/bin/bash
DELAY=${DELAY:-10}
LOOP=${LOOP:-0}
r=`realpath $1`
d=`dirname $r`
pushd $d > /dev/null
f=`basename $r`
n=`webpinfo -summary $f | grep frames | sed -e 's/.* \([0-9]*\)$/\1/'`
dur=`webpinfo -summary $f | grep Duration | head -1 | sed -e 's/.* \([0-9]*\)$/\1/'`
if (( $dur > 0 )); then
DELAY = dur
fi
pfx=`echo -n $f | sed -e 's/^\(.*\).webp$/\1/'`
if [ -z $pfx ]; then
pfx=$f
fi
echo "converting $n frames from $f
working dir $d
file stem '$pfx'"
for i in $(seq -f "%05g" 1 $n)
do
webpmux -get frame $i $f -o $pfx.$i.webp
dwebp $pfx.$i.webp -o $pfx.$i.png
done
convert $pfx.*.png -delay $DELAY -loop $LOOP $pfx.gif
rm $pfx.[0-9]*.png $pfx.[0-9]*.webp
popd > /dev/null
@idolpx

idolpx commented Sep 13, 2019

Copy link
Copy Markdown
Author

Solution source: https://unix.stackexchange.com/questions/419761/webp-animation-to-gif-animation-cli

If you get "realpath: command not found" on OSX be sure to use Homebrew and install "coreutils".

brew install coreutils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment