发布网友 发布时间:2022-04-22 10:44
共1个回答
热心网友 时间:2023-11-01 23:47
from PIL import Image
import os.path
import glob
def 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?