python 删除某一文件夹下的 大小小于特定值的图片

import os
from PIL import Image
import glob
dir1 = './VOC2012/JPEGImages'  # 图片文件存放地址

paths = glob.glob(os.path.join(dir1, '*.jpg'))
# 输出所有文件和文件夹
for file in paths:
    fp = open(file, 'rb')
    img = Image.open(fp)
    fp.close()
    width = img.size[0]
    height = img.size[1]
    if (width <= 360) or (height <= 380):
        os.remove(file)

你可能感兴趣的:(毕设)