Created
May 11, 2024 23:15
-
-
Save VIRUXE/daae80cdf192079af2411a371bd98f7b to your computer and use it in GitHub Desktop.
Convert PNG images to WebP, using Pillow
This file contains 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 os | |
from PIL import Image | |
import sys | |
for root, dirs, files in os.walk(sys.argv[1] if len(sys.argv) > 1 else "."): | |
for file in files: | |
if file.endswith('.png'): | |
png_path = os.path.join(root, file) | |
webp_path = png_path.replace('.png', '.webp') | |
Image.open(png_path).convert("RGBA").save(webp_path, "WEBP", quality=100) | |
print(f"{png_path} -> {webp_path}") | |
if not '--recursive' in sys.argv: break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment