I want to create Gif file with many Png files. The problem is the Png files has date within their names e.g. (name_2017100706_var.png). The dates start are in yymmddhh format and start at 2017100706 end at 2017101712, with increment of 6 hrs, so the next file name will contain 2017100712 in its name, and I want the code to loop over the files sequentially according to the dates. So I am using the following code:
import os
import imageio
import datetime
png_dir = '/home/path/'
images = []
counter = 2017100706
while counter <= 2017101712:
for file_name in os.listdir(png_dir):
if file_name.startswith('name_'+str(counter)):
file_path = os.path.join(png_dir, file_name)
images.append(imageio.imread(file_path))
counter +=6
imageio.mimsave('/home/path/movie.gif', images, duration = 1)