Last active
          December 16, 2023 07:36 
        
      - 
      
- 
        Save idolpx/a0e4fecbaeaaf79f8e9e48b5d622bfa9 to your computer and use it in GitHub Desktop. 
    Converts a .WEBP file to animated .GIF
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/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 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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