2018-08-07

2018-08-07  本文已影响23人  道法自然FOAF

在python中使用pillow修改图片的尺寸大小

from PIL import Image

readfile_path=r'./template.png'  #当前图片的路径(相对路径)

outfile_path=r'./template.png'  #图片保存在当前路径

width=38  #宽度

length=38  #长度

Image.open(readfile_path).convert('RGB').save(outfile_path) # convert the image to RGB mode  very important 将图片转化为RGB模式

img = Image.open(readfile_path)

print(img.format, img.size, img.mode, img.info)

newImg = img.resize((width,length), Image.ANTIALIAS)  #想调整的大小

print(newImg)

newImg.save(outfile_path)

上一篇 下一篇

猜你喜欢

热点阅读