2018-08-07

在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)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容