#提取目录下所有图片,更改尺寸后保存到另一目录
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.youkuaiyun.com/atyzy/article/details/77905463
批量调整图片尺寸

本文介绍了一种使用Python和PIL库批量调整图片尺寸的方法。通过定义一个函数convertjpg,可以读取指定目录下的所有.jpg文件,调整其尺寸为128x128像素,并保存到另一个指定目录。
1401

被折叠的 条评论
为什么被折叠?



