python PIL 单张图像变换大小—— img.resize()

from PIL import Image
'''
filein: 输入图片
fileout: 输出图片
width: 输出图片宽度
height:输出图片高度
type:输出图片类型(png, gif, jpeg...)
'''


def ResizeImage(filein, fileout, width, height, type):
    img = Image.open(filein)
    out = img.resize((width, height),Image.ANTIALIAS) #resize image with high-quality
    out.save(fileout, type)


if __name__ == "__main__":
    filein = r'0.jpg'
    fileout = r'testout.png'
    width = 512
    height = 512
    type = 'png'
    ResizeImage(filein, fileout, width, height, type)

这个函数img.resize((width, height),Image.ANTIALIAS) 
第二个参数: 
Image.NEAREST :低质量 
Image.BILINEAR:双线性 
Image.BICUBIC :三次样条插值 
Image.ANTIALIAS:高质量

你可能感兴趣的:(python)