import os
img_folder = ''
img_list = [os.path.join(img_folder, nm) for nm in os.listdir(img_folder) if nm[-3:] in ['jpg','png','gif']]
img_list.sort()
Picture suggest that you named when not simply use a single number, so that the picture sort sorting time, there will be 11.jpg
ranked in 2.jpg
front of the
suggested adding zfill()
the above-mentioned problems to avoid ordering
idx = 1
img_name = str(idx).zfill(3)+'.jpg'
Will get001.jpg