当前位置:主页 > 软件编程 > Python代码 >

用python 批量更改图像尺寸到统一大小的方法

时间:2021-03-14 09:48:04 | 栏目:Python代码 | 点击:

如下所示:

#提取目录下所有图片,更改尺寸后保存到另一目录
from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=128,height=128):
  img=Image.open(jpgfile)
  try:
    new_img=img.resize((width,height),Image.BILINEAR)  
    new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
  except Exception as e:
    print(e)
for jpgfile in glob.glob("E:\\img\\*.jpg"):
  convertjpg(jpgfile,"E:\\lianhua")
  

您可能感兴趣的文章:

相关文章