批量修改图片大小Python代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# -*- coding: utf-8 -*-
'''
 
'''
import os
from PIL import Image
 
pic_dir = r"H:\新建文件夹"
for filename in os.listdir(path=pic_dir):
    if filename.startswith("SAM"):
        pic_path = os.path.join(pic_dir, filename)
        print (pic_path)
        img = Image.open(pic_path )
        new_size = tuple( [ size//3 for size in img.size]  ) # 高度、宽度均变为原来的1/3
        new_img = img.resize( new_size)
        new_name = os.path.join(pic_dir, "small_" + filename)
        new_img.save(new_name )