#coding=utf-8 import os import os.path from PIL import Image 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'test.jpg' fileout = r'testout.jpg' width = 28 height = 28 type = 'jpeg'#类型可以改 ResizeImage(filein, fileout, width, height, type)
注意图片类型有:jpeg格式,不要写成jpg格式否则会报KeyError:Jpg