1 pip install imageio
2 代碼
import imageio
def img_to_gif(img_list, gif_name):
all_frames = []
for img_path in img_list:
img = imageio.imread(img_path)
all_frames.append(img)
imageio.mimsave(gif_name, all_frames, 'GIF', duration=1)
return
if __name__ == '__main__':
img_list = ["test_img/1.jpg", "test_img/2.jpg", "test_img/3.jpg", "test_img/4.jpg"]
gif_name = "result.gif"
img_to_gif(img_list, gif_name)
pass