Created
August 11, 2022 19:44
-
-
Save opub/83ff3c8310e998ff59bf77a615570490 to your computer and use it in GitHub Desktop.
Generates an animated GIF for set of images in a directory
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
from PIL import Image | |
import glob | |
import math | |
# | |
# This script will take all of the images that match a pattern in the local | |
# directory and generate an animated GIF with each image as a frame. Useful | |
# for capturing all of your NFTs into a single file for sharing. | |
# | |
# One time setup assuming you already have python and pip installed. | |
# pip install Pillow | |
# | |
# Usage: | |
# python animate.py | |
# | |
pattern = "MKRS*.jpeg" | |
output = "MKRS.gif" | |
# create the individual frames from each file (resized to 1/4 of original to keep gif smaller) | |
frames = [] | |
imgs = glob.glob(pattern) | |
for i in imgs: | |
new_frame = Image.open(i) | |
width, height = new_frame.size | |
frames.append(new_frame.resize((math.floor(width/2), math.floor(height/2)))) | |
# save into a GIF file that loops forever | |
frames[0].save(output, format="GIF", append_images=frames[1:], save_all=True, duration=300, loop=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment