Pillow
安装
python2 -m pip install Pillow
pip3 install Pillow加载图片,使用方法open
from PIL import Image
im = Image.open('test.jpg')
im.show()
# show 会调用系统默认的图片浏览器,linux好像不行,windows下正常
print im.format,im.size,im.mode
# im是一个Image对象,属性有format,size,mode。format是格式,size 是一个元组,表示(宽,高),mode则指的图片的模式。图片的读和写
infile = 'test.jpg'
f,e = os.path.splitext(infile)
outfile = f + '.png'
try:
Image.open(infile).save(outfile)
except IOError:
print "cannot convert",infile