from PIL import Image
import os.path
import glob #该方法返回所有匹配的文件路径列表(list)
Datadir = "./initial_data/*.jpg"
savedir = "./resize_240/images"
def convertjpg(jpgfile,outdir,width=240,height=240):
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(Datadir):
convertjpg(jpgfile,savedir)
代码:批量图片resize
最新推荐文章于 2023-03-27 12:09:23 发布