Python PIL属性的Image.width方法

Python PIL属性的Image.width方法

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

图片类有宽度属性。

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

语法: PIL.Image.width

参数:
image – 使用不同扩展的图像。

返回:图像的宽度

使用的图片:
Python PIL属性的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的图片。

使用的图片:
Python PIL属性的Image.width方法

   
  
# 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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程