Creating Animated GIFs using Python

from PIL import Image
import glob #use it if you want to read all of the certain file type in the directory
imgs=[ ]
for i in range(596,691):
   imgs.append("snap"+str(i)+'.png')
   print("scanned the image identified with",i)

#starting and ending value+1 of the index that identifies different file names

imgs = glob.glob("*.png") #do this if you want to read all files ending with .png

#my files were: snap596.png, snap597.png ...... snap690.png

frames = []
for i in imgs:
  new_frame = Image.open(i)
  frames.append(new_frame)

#Save into a GIF file that loops forever

frames[0].save('fire3_PIL.gif', format='GIF',append_images=frames[1:],save_all=True,duration=300, loop=0)

#I found flickering issue with imageio and this method fixed it.