Created
November 3, 2017 12:48
-
-
Save skywodd/8b68bd9c7af048afcedcea3fb1807966 to your computer and use it in GitHub Desktop.
Resize GIF image using Python Pillow library
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, ImageSequence | |
# Output (max) size | |
size = 320, 240 | |
# Open source | |
im = Image.open("in.gif") | |
# Get sequence iterator | |
frames = ImageSequence.Iterator(im) | |
# Wrap on-the-fly thumbnail generator | |
def thumbnails(frames): | |
for frame in frames: | |
thumbnail = frame.copy() | |
thumbnail.thumbnail(size, Image.ANTIALIAS) | |
yield thumbnail | |
frames = thumbnails(frames) | |
# Save output | |
om = next(frames) # Handle first frame separately | |
om.info = im.info # Copy sequence info | |
om.save("out.gif", save_all=True, append_images=list(frames)) |
oh wow tysm!
Thank you so much! My boss doesn't blame me now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much! It helped a lot :)