Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Last active February 11, 2024 22:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcgeek86/ae55fada48e6cf25516f2e064cfd0edb to your computer and use it in GitHub Desktop.
Save pcgeek86/ae55fada48e6cf25516f2e064cfd0edb to your computer and use it in GitHub Desktop.
Convert an animated .webp file to GIF with Python
#!/usr/bin/env python3
# Trevor Sullivan <trevor@trevorsullivan.net>
# https://trevorsullivan.net
# https://twitter.com/pcgeek86
# IMPORTANT: Install the webp Python package, using the following command:
# pip3 install --user webp
# Import the webp package
import webp
# Load a PIL image array from the specified .webp animation file
anim = webp.load_images('giphy.webp')
# Grab a reference to the first frame, and save the entire PIL image array as GIF with 70ms frames (14.286 FPS)
anim[0].save('output.gif', save_all=True, append_images=anim[0:], duration=70, loop=0)
@FeraruSilviuMarian
Copy link

FeraruSilviuMarian commented Sep 13, 2021

The two methods (webp and PIL) yield the same poor image quality, the colors are fewer, the colors feel 8 bit or so

`import webp
from PIL import Image

im = Image.open(r'C:\Users\silve\Downloads\25036996.webp')
im.info.pop('background', None)
im.save(r'C:\Users\silve\Downloads\test.gif', 'gif', save_all=True)

anim = webp.load_images(r'C:\Users\silve\Downloads\25036996.webp')
anim[0].save(r'C:\Users\silve\Downloads\test2.gif', save_all=True, append_images=anim[0:], duration=70, loop=0)`

@Mostalk
Copy link

Mostalk commented May 12, 2022

Hi, ty for this script. But, after conver my gif is very speed up? How to increase speed?

@tzelalouzeir
Copy link

i

from PIL import Image

import requests
from io import BytesIO

#webp to gif convert
#webp link
url = 'https://cdn.7tv.app/emote/60a9cfe96daf811370b0b640/4x.webp'
#save image destination
destination = 'output1.gif'

response = requests.get(url)
img = Image.open(BytesIO(response.content))
img.save(destination,'gif',save_all=True)

founded from: https://groups.google.com/a/webmproject.org/g/webp-discuss/c/VcfpaZ0fJeM?pli=1

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