📜  Python PIL 属性 | Image.width 方法

📅  最后修改于: 2022-05-13 01:54:53.982000             🧑  作者: Mango

Python PIL 属性 | Image.width 方法

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 Image模块提供了一个同名的类,用于表示 PIL 图像。该模块还提供了许多工厂函数,包括从文件加载图像和创建新图像的函数。

Image类具有宽度属性。

Image.width图像宽度,以像素为单位。属性定义对象、元素或文件的各种属性。

使用的图像:

# importing Image module from PIL package 
from PIL import Image 
  
# opening a  image 
im = Image.open(r"C:\Users\System-Pc\Desktop\flower1.jpg") 
  
# width attribute
im1 = im.width
print(im1)

输出:

225

另一个例子:获取另一个扩展名为 .png 的图像。

使用的图像:

# importing Image module from PIL package 
from PIL import Image 
  
# opening a  image 
im = Image.open(r"C:\Users\System-Pc\Desktop\python.png") 
  
# width attribute
im1 = im.width
print(im1)

输出:

220