Image类的属性:
一:format
含义:源文件的文件格式。如果是由PIL创建的图像,则其文件格式为None。
例子:
from PIL import Image
im=Image.open("D:\\22.jpg")
print(im.format)
输出为 JPEG
注:在输入文件路径的时候,要注意格式,否则容易报错,可以参考blog:https://blog.youkuaiyun.com/cuicui_ruirui/article/details/104587540
二:mode
含义:图像的模式。这个字符串表明图像所使用像素格式。该属性典型的取值为“1”,“L”,“RGB”或“CMYK”。
from PIL import Image
im=Image.open("d:/22.jpg")
print(im.mode)
输出为 RGB
三:size
含义:图像的尺寸,按照像素数计算。它的返回值为宽度和高度的二元组(width, height)。
from PIL import Image
im=Image.open("d:/22.jpg")
print(im.size)
输出为(1080,1080)
四:palette
含义:颜色调色板表格。如果图像的模式是“P”,则返回ImagePalette类的实例;否则,将为None。
from PIL import Image
im=Image.open("d:/22.jpg")
print(im.palette)
因为该图像是JEPG模式,输出结果为 None
本文详细介绍了Python图像处理库PIL中Image类的四个关键属性:format、mode、size和palette。通过具体示例展示了如何获取图像的文件格式、模式、尺寸及颜色调色板,为图像处理提供基础指南。
5万+

被折叠的 条评论
为什么被折叠?



