批量修改图片大小Python代码,,# -*- coding


# -*- coding: utf-8 -*-''''''import osfrom PIL import Imagepic_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 )

评论关闭