Last active
February 11, 2024 22:18
-
-
Save pcgeek86/ae55fada48e6cf25516f2e064cfd0edb to your computer and use it in GitHub Desktop.
Convert an animated .webp file to GIF with Python
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
#!/usr/bin/env python3 | |
# Trevor Sullivan <[email protected]> | |
# 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) |
Hi, ty for this script. But, after conver my gif is very speed up? How to increase speed?
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
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)`