22 lines
768 B
Python
22 lines
768 B
Python
|
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}")
|