一、需求:
批量修改该图片长与宽尺寸
二、素材:
三、代码:
from PIL import Image
import os.path
import globdef 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:\Users\aaa\Desktop\1\2\3\*.jpg"
for jpgfile in glob.glob(path):convertjpg(jpgfile,r"C:\Users\aaa\Desktop\li")
四、结果