from PIL import Imageimport os.pathimport globdef convertjpg(jpgfile,outdir,width=1280,height=720): 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("D:/python/*.jpg"): convertjpg(jpgfile,"D:/newfile")
convertjpg调用时可以有四个参数,如convertjpg(jpgfile,"D:/newfile",800,600)
Image open了jpg用完后要不要close?