I need to create a GIF from the last seven newest images from a directory. The directory is constantly updating and adding new images every 10 minutes, so I already could make the code to create the GIF including all the files in the directory, but I need to be more specific and just create a GIF from the last seven newest images. In conclusion: I need to specify the limit of images which my code has to grab to create the GIF.. Below is the code so far:
import imageio
import os
import time
now = time.time()
png_dir = 'C:/Users/dchacon/Desktop/Destino/'
images = []
for file_name in os.listdir(png_dir):
if file_name.endswith('.png'):
file_path = os.path.join(png_dir, file_name)
images.append(imageio.imread(file_path))
imageio.mimsave('C:/Users/dchacon/Desktop/Destino/NTMPCA.gif', images, fps=1)