在python中实现图片尺寸变换。

#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

猜你喜欢

转载自blog.csdn.net/zhuiyunzhugang/article/details/85929753
今日推荐