根据图片的分辨率进行分类

# -*- coding: utf-8 -*-
"""
Created on Tue May 27 19:28:48 2025

@author: F1_tsp6
"""

import os
import shutil
from PIL import Image

if __name__ == '__main__':
    pic_path = '自己的路径'
    files = os.listdir(pic_path)
    for file in files:
        source=pic_path +'/'+ file
        if os.path.isfile(source):
            try:
                img = Image.open(source)
                imgSize = img.size #图片的长和宽
                img.close()
                folder_name = str(imgSize[0])+'x'+str(imgSize[1])
                path = pic_path +'/'+ folder_name
                os.makedirs(path, exist_ok=True)
                shutil.move(source, path)
                print('移动到'+folder_name)
            except:
                continue

 

posted @ 2025-05-30 09:45  color_bar  阅读(6)  评论(0)    收藏  举报