Skip to content

Instantly share code, notes, and snippets.

@notchum
Created January 4, 2023 22:38
Show Gist options
  • Save notchum/54dbc703797c2ecdfb632a4cbe1ba42d to your computer and use it in GitHub Desktop.
Save notchum/54dbc703797c2ecdfb632a4cbe1ba42d to your computer and use it in GitHub Desktop.
Convert WEBP files that should be GIF files into the GIF format.
:: Drag & drop the WEBP file onto this batch script. CLI free!
"python.exe" %~dp0\webp2gif.py %*
# 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