我是靠谱客的博主 精明鸵鸟,这篇文章主要介绍图片操作案例:python 批量更改图像尺寸到统一大小的方法一、需求:二、素材:三、代码:四、结果,现在分享给大家,希望可以做个参考。

一、需求:

批量修改该图片长与宽尺寸

二、素材:

三、代码:

from PIL import Image
import os.path
import glob

def convertjpg(jpgfile,outdir,width=512,height=512):
  img=Image.open(jpgfile)
  try:
    new_img=img.resize((width,height),Image.BILINEAR)
    if not os.path.exists(outdir):
        os.mkdir(outdir)
    new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
  except Exception as e:
    print(e)

path = r"C:UsersaaaDesktop123*.jpg"
for jpgfile in glob.glob(path):
  convertjpg(jpgfile,r"C:UsersaaaDesktopli")

四、结果

 

最后

以上就是精明鸵鸟最近收集整理的关于图片操作案例:python 批量更改图像尺寸到统一大小的方法一、需求:二、素材:三、代码:四、结果的全部内容,更多相关图片操作案例:python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部