在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`替换为你的图片文件的实际路径。运行上述代码后,你将得到图片的宽度和高度。

