如何在特定文件夹中查找大小不是 2 的倍数的图像?

How to find images in a specific folder with a size not multiple of 2?

我有一些包含大约 200 张图片的文件夹,我想突出显示尺寸不是 2 的倍数的图片。

有没有有效的方法?

此致!

这是一个 Python 脚本,它打印所有尺寸不是 2 的倍数的图像。它只是找到所有图像并使用 PIL 来获取尺寸。

import glob
from PIL import Image

# Get all images
image_path = 'PATH TO YOUR IMAGES'
images = glob.glob(image_path + '/**.png')  # Depending on your images extension
images_not_pair = []

# For all images open them with PIL and get the image size
for image in images:
    with Image.open(image) as im:
        width, height = im.size
        if width % 2 is not 0 or height % 2 is not 0:
            images_not_pair.append(image)

print(images_not_pair)