import os
from PIL import Image
# 指定要处理的文件夹路径
folder_path = r'E:\压缩包合集\VOC2028\VOC2028\JPEGImages'
# 获取文件夹中所有图片文件的路径
image_files = [f for f in os.listdir(folder_path) if f.lower().endswith(('jpg', 'jpeg', 'png', 'gif'))]
# 存储要删除的图片文件路径
images_to_delete = []
# 遍历处理每个图片文件
for image_file in image_files:
image_path = os.path.join(folder_path, image_file)
with Image.open(image_path) as img:
width, height = img.size
if width >= 700 or height >= 700:
images_to_delete.append(image_path)
print(f'Image "{image_file}" marked for deletion (width:{width}, height:{height})')
# 删除标记的图片文件
for image_path in images_to_delete:
os.remove(image_path)
print(f'Image "{os.path.basename(image_path)}" deleted')
删除特定大小的图片
最新推荐文章于 2024-05-18 14:47:53 发布