Python 批量修改图片尺寸

from PIL import Image
import os.path
import glob

def Resize(file, outdir, width, height):
    imgFile = Image.open(file)
    try:
        newImage = imgFile.resize((width, height), Image.BILINEAR)   
        newImage.save(os.path.join(outdir, os.path.basename(file)))
    except Exception as e:
        print(e)


for file in glob.glob("F:\\facereg\\image\\Tony_Blair\\*.jpg"):  # 图片所在的目录
    Resize(file, "F:\\facereg\\nimage\\Tony_Blair", 224, 224)    # 新图片存放的目录

 

你可能感兴趣的:(Python)