在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}')

