# -*- 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 )
原文:http://my.oschina.net/cppblog/blog/500308