Last active
December 19, 2017 21:55
-
-
Save jewbetcha/b98f26d067abee9432be5baaddef6da6 to your computer and use it in GitHub Desktop.
Deconstruct a gif into individual frames
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
#!/usr/bin/env python3 | |
# $ ./deconstruct.py path_to_gif.gif output/path/ | |
# Will output the frames to the specified directory. | |
import sys | |
import os | |
import time | |
from PIL import Image | |
def deconstruct_gif(gif, out_dir): | |
if not os.path.isdir(out_dir): | |
os.makedirs(out_dir) | |
frame = Image.open(gif) | |
i = 0 | |
print("Deconstructing your gif...") | |
while frame: | |
time.sleep(.01) | |
frame.save('%s/%s-%s.png' % (out_dir, os.path.basename(gif), i) , 'PNG') | |
i += 1 | |
sys.stdout.write("-") | |
sys.stdout.flush() | |
try: | |
frame.seek(i) | |
except EOFError: | |
break; | |
sys.stdout.write("\n") | |
return True | |
def main(): | |
image = ''.join(sys.argv[1:][0]) | |
path = ''.join(sys.argv[1:][1]) | |
deconstruct_gif(image, path) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment