generate gif py code example
Example 1: make gif from images in python
from PIL import Image
import glob
frames = []
imgs = glob.glob("*.png")
for i in imgs:
new_frame = Image.open(i)
frames.append(new_frame)
frames[0].save('png_to_gif.gif', format='GIF',
append_images=frames[1:],
save_all=True,
duration=300, loop=0)
Example 2: make gif from images in python
import glob
import os
gif_name = 'outputName'
file_list = glob.glob('*.png')
list.sort(file_list, key=lambda x: int(x.split('_')[1].split('.png')[0]))
with open('image_list.txt', 'w') as file:
for item in file_list:
file.write("%s\n" % item)
os.system('convert @image_list.txt {}.gif'.format(gif_name))
Example 3: generate gif py
import imageio
images = []
for filename in filenames:
images.append(imageio.imread(filename))
imageio.mimsave('/path/to/movie.gif', images)
Example 4: generate gif py
import imageio
with imageio.get_writer('/path/to/movie.gif', mode='I') as writer:
for filename in filenames:
image = imageio.imread(filename)
writer.append_data(image)