Embedded_game/图片尺寸检查.py

22 lines
768 B
Python
Raw Normal View History

2025-02-25 18:51:58 +08:00
import os
from PIL import Image
# 指定要检查的目录路径
directory = r"C:\Users\10561\Downloads\Compressed\images" # 替换为你的目录路径
# 目标尺寸
target_size = (224, 224)
# 遍历目录中的所有文件
for filename in os.listdir(directory):
# 只处理图片文件(根据文件后缀判断)
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
file_path = os.path.join(directory, filename)
try:
with Image.open(file_path) as img:
# 检查图片尺寸是否与目标尺寸不一致
if img.size != target_size:
print(f"{filename}: {img.size}")
except Exception as e:
print(f"处理 {filename} 时出错: {e}")