在Python中,你可以使用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}')
请确保将`file_path`替换为你的图片文件的实际路径。运行上述代码后,你将得到图片的宽度和高度。