Give this folders as arguments, and it will display all the images in those folders as quickly as possible, letting you skim through large collections of similar images, for instance.
Last active
July 1, 2021 16:57
-
-
Save endolith/50e50ad6b2b16d319e5f7df0acc184d1 to your computer and use it in GitHub Desktop.
Display a folder of images very quickly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import Tk, Label | |
from PIL import Image, ImageTk | |
import os | |
import sys | |
# Skip every n frames. Use 1 to show all images | |
skip = 1 | |
try: | |
root = Tk() | |
image = Image.new(mode='RGB', size=(640, 480)) | |
photo = ImageTk.PhotoImage(image) | |
img = Label(root, image=photo) | |
for folder in sys.argv[1:]: | |
n = 0 | |
files = os.listdir(folder) | |
for filename in files[::skip]: | |
filename = folder + '/' + filename | |
try: | |
image = Image.open(filename) | |
except IOError: | |
continue | |
n += 1 | |
photo = ImageTk.PhotoImage(image) | |
img.configure(image=photo) | |
img.pack() | |
root.update() | |
print('Displayed {} of {} files in {}'.format(n, len(files), | |
folder.split('\\')[-1])) | |
root.mainloop() | |
except Exception as err: | |
print(err) | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really neat and efficient!