在Python中,你可以使用Pillow库(PIL库的更新版)来获取图片的宽度和高度。以下是使用Pillow库获取图片尺寸的步骤和代码示例:
1. 安装Pillow库(如果尚未安装):
pip install pillow
2. 使用Pillow库获取图片尺寸的代码示例:
from PIL import Image
指定图片路径
file_path = 'path/to/your/image.jpg'
打开图片
img = Image.open(file_path)
获取图片的宽度和高度
width, height = img.size
打印图片的宽度和高度
print(f'图片的宽度是:{width}, 高度是:{height}')