Python提供了图片处理的库PIL(Python Image Library),功能十分强大,下面介绍使用PIL进行图片的缩放。
1、安装PIL库
使用pip进行安装,安装命令为pip install Pillow,安装完成之后,from PIL import Image来检验是否安装成功。
2、代码实现
下面这两篇博客介绍Image的常用方法
将分辨率为124*124的图片,压缩为50*50
from PIL import Image
img = Image.open("test.png")
print img.size
out = img.resize((50,50))
out.save("new.png")