1.依赖
pip install pillow
2.修改图片尺寸
from PIL import Image
'''
filein: 输入图片
fileout: 输出图片
width: 输出图片宽度
height:输出图片高度
type:输出图片类型(png, gif, jpeg...)
'''
def ResizeImage(filein, fileout, width, height, img_type):
img = Image.open(filein)
out = img.resize((width, height), Image.ANTIALIAS)
# resize image with high-quality
out.save(fileout, img_type)
if __name__ == "__main__":
filein = r'path\1.jpeg'
fileout = r'path\2.jpeg'
width = 100
height = 100
img_type = 'jpeg'
ResizeImage(filein, fileout, width, height, img_type)