python更改图像尺寸resize

from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=256,height=256):
    img=Image.open(jpgfile)
    h, w = img.size
    if h != 256 or w != 256:
        try:
            print(jpgfile,h,w)
            new_img=img.resize((width,height),Image.NEAREST)   #ANTIALIAS
            new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
        except Exception as e:
            print(e)
for jpgfile in glob.glob("./9-crack776/mask-yuan/*"):
    convertjpg(jpgfile,"./9-crack776/mask")

猜你喜欢

转载自blog.csdn.net/weixin_42535423/article/details/121888875