1from PIL import Image
2import glob
3
4# Create the frames
5frames = []
6imgs = glob.glob("*.png")
7for i in imgs:
8 new_frame = Image.open(i)
9 frames.append(new_frame)
10
11# Save into a GIF file that loops forever
12frames[0].save('png_to_gif.gif', format='GIF',
13 append_images=frames[1:],
14 save_all=True,
15 duration=300, loop=0)
16
1import glob
2import os
3
4gif_name = 'outputName'
5file_list = glob.glob('*.png') # Get all the pngs in the current directory
6list.sort(file_list, key=lambda x: int(x.split('_')[1].split('.png')[0])) # Sort the images by #, this may need to be tweaked for your use case
7
8with open('image_list.txt', 'w') as file:
9 for item in file_list:
10 file.write("%s\n" % item)
11
12os.system('convert @image_list.txt {}.gif'.format(gif_name)) # On windows convert is 'magick'
13
1import imageio
2with imageio.get_writer('/path/to/movie.gif', mode='I') as writer:
3 for filename in filenames:
4 image = imageio.imread(filename)
5 writer.append_data(image)