I have a directory with lots of images. I'm trying to create a gif from them. Everything works, except that the method I'm using to sort the images doesn't sort them exactly:
#save images as gif
import glob
from PIL import Image
# filepaths
fp_in = "images/epoch*.png"
fp_out = "images/vid.gif"
# https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif
img, *imgs = [Image.open(f) for f in sorted(glob.glob(fp_in))]
img.save(fp=fp_out, format='GIF', append_images=imgs,
save_all=True, duration=500) #, loop=0
When I print sorted(glob.glob(fp_in))
I get
['images/epoch0.png',
'images/epoch1000.png',
'images/epoch10000.png',
'images/epoch11000.png',
'images/epoch12000.png',
'images/epoch13000.png',
'images/epoch14000.png',
'images/epoch15000.png',
'images/epoch16000.png',
'images/epoch17000.png',
'images/epoch18000.png',
'images/epoch19000.png',
'images/epoch2000.png',
'images/epoch20000.png',
...
You can see that it goes from 1000 to 10000, and from 2000 to 20000, etc. What is the correct way to do that?