Last active
September 3, 2023 07:31
-
-
Save ashishkulkarnii/999e1e2d928f4a3c2f8a09b1e3c08fd6 to your computer and use it in GitHub Desktop.
Convert PNG files to a single GIF, using only PIL library,
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
| """Convert all PNG files in a folder passed to this program into a single GIF file, sorted by filename.""" | |
| from PIL import Image | |
| import os | |
| import sys | |
| if len(sys.argv) < 2: | |
| print("Usage: python png_to_gif.py <folder>") | |
| sys.exit(1) | |
| folder = sys.argv[1] | |
| files = os.listdir(folder) | |
| files.sort() | |
| images = [] | |
| for file in files: | |
| if file.endswith(".png"): | |
| images.append(Image.open(os.path.join(folder, file))) | |
| images[0].save(os.path.join(folder, "out.gif"), save_all=True, append_images=images[1:], duration=100, loop=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment