网络编程
位置:首页>> 网络编程>> Python编程>> 用python 批量更改图像尺寸到统一大小的方法

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

作者:atyzy  发布时间:2021-04-04 23:47:42 

标签: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")
 

来源:https://blog.csdn.net/atyzy/article/details/77905463

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com