I need to check the dimensions of images in a directory. Currently it has ~700 images. I just need to check the sizes, and if the size does not match a given dimension, it w
import os from PIL import Image folder_images = "/tmp/photos" size_images = dict() for dirpath, _, filenames in os.walk(folder_images): for path_image in filenames: image = os.path.abspath(os.path.join(dirpath, path_image)) with Image.open(image) as img: width, heigth = img.size SIZE_IMAGES[path_image] = {'width': width, 'heigth': heigth} print(size_images)
In folder_images
you arrow directory where it is imagens.
size_images
is a variable with the size of the images, in this format.
Example {'image_name.jpg' : {'width': 100, 'heigth': 100} }