编程语言
首页 > 编程语言> > python 照片更改尺寸

python 照片更改尺寸

作者:互联网

from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=150,height=200):
    img=Image.open(jpgfile)
    try:
        new_img = img.resize((width, height), Image.BILINEAR)
        if new_img.mode == 'P':
            new_img = new_img.convert("RGB")
        if new_img.mode == 'RGBA':
            new_img = new_img.convert("RGB")
        new_img.save(os.path.join(outdir, os.path.basename(jpgfile)))
    except Exception as e:
        print(e)

for jpgfile in glob.glob("C:/Users/app/Pictures/in/me.jpg"):
    # print(jpgfile)
    convertjpg(jpgfile,"C:/Users/app/in/out")

标签:img,更改,python,glob,jpgfile,尺寸,import,new,path
来源: https://blog.csdn.net/weixin_42788078/article/details/121655443