批量调整图像大小程序.py

"""批量调整图像大小程序.py,本程序会把文件夹下面所有的图片缩小一半"""

import os
from PIL import Image

path = "F:\\www.scratch8.net\Python教程"
os.chdir(path)

scale = 0.5
counter = 0
for filename in os.listdir():
    print("开始处理图像文件:",filename)
    im = Image.open(  filename)
    width,height = im.size
    width,height = int(width * scale) ,int(height * scale)
    im = im.resize((width,height))
    im.save(filename)
    im.close()
    counter += 1   # 统计

print("批处理图像完毕,共处理了:",counter,"个文件")
print("请自行对本程序进行完善,脚本简单旨在抛砖引玉.")