Python读取图片尺寸、图片格式

Python读取图片尺寸、图片格式

需要用到PIL模块,使用pip安装Pillow.Pillow是从PIL fork过来的Python 图片库。

from PIL import Image
im = Image.open(filename)#返回一个Image对象
print('宽:%d,高:%d'%(im.size[0],im.size[1]))

Image类的属性##

PIL.Image.format

图片生成时的原格式,不是以文件后缀名为依据。

类型: string or None

PIL.Image.mode

*图片模式。图片使用的像素格式,典型的格式有 “1”, “L”, “RGB”, or “CMYK.” *

类型: string

PIL.Image.size

图片尺寸(以像素为单位).

类型: (width, height)

PIL.Image.width

图片像素宽

类型: int

PIL.Image.height

图片像素高

类型: int

PIL.Image.palette

调色板。如果模式是“P”,则是一个ImagePalette类的实例。

类型: ImagePalette or None

PIL.Image.info

一个与图片有关的数据组成的字典。

类型: dict

原文地址:https://www.cnblogs.com/d0main/p/7613296.html