【python】PIL resize图片

PIL库进行图片的resize

from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=768,height=384):
    img=Image.open(jpgfile)   
    new_img=img.resize((width,height),Image.BILINEAR)   
    new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))


for jpgfile in glob.glob("./training/image_2/*.png"):
    convertjpg(jpgfile,"./training_resize/image_2/")

github连接如下:

你可能感兴趣的:(Python笔记)