Last active
January 8, 2022 10:43
-
-
Save TutorialDoctor/7562ddca4b820c246682efcd752172b6 to your computer and use it in GitHub Desktop.
Convert gif to png images
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 | |
from PIL import GifImagePlugin | |
import os,time,zipfile | |
imageObject = Image.open("./source.gif") | |
# info = imageObject.info | |
for frame in range(0,imageObject.n_frames): | |
imageObject.seek(frame) | |
#imageObject.info['transparency'] = 255 | |
# imageObject.show() | |
try: | |
os.mkdir('data') | |
except: | |
None | |
imageObject.save("./data/{}".format(frame) + ".png", transparency=255, disposal=2) | |
# ZIP DIRECTORY | |
zf = zipfile.ZipFile("output.zip", "w") | |
for dirname, subdirs, files in os.walk("data"): | |
zf.write(dirname) | |
for filename in files: | |
zf.write(os.path.join(dirname, filename)) | |
zf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment