Created
January 4, 2023 22:38
-
-
Save notchum/54dbc703797c2ecdfb632a4cbe1ba42d to your computer and use it in GitHub Desktop.
Convert WEBP files that should be GIF files into the GIF format.
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
:: Drag & drop the WEBP file onto this batch script. CLI free! | |
"python.exe" %~dp0\webp2gif.py %* |
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
# Import the webp package | |
import webp, sys, os, shutil | |
for i in sys.argv[1:]: | |
# Get filename | |
fn = os.path.basename(i) | |
# Strip extension | |
fp = os.path.splitext(i) | |
print(f"Processing {fp[0]}.gif") | |
# Load a PIL image array from the specified .webp animation file | |
anim = webp.load_images(i) | |
# 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(f'{fp[0]}.gif', save_all=True, append_images=anim[0:], duration=70, loop=0) | |
# Archive the .webp animation | |
dest = f'{sys.path[0]}\\webp_archive' | |
if not os.path.exists(dest): os.mkdir(dest) | |
shutil.move(i, f'{dest}\\{fn}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment