如何获取已经以字节为单位的图像的大小和分辨率

How to get size and resolution on image that already in bytes

我想知道是否有某种方法可以获取 python 中已经以字节为单位的图像的大小和分辨率,我试图搜索它并且它正在使用外部库..你是吗是否知道如何通过外部库来完成。

谢谢

你可以使用 PIL(枕头)。

安装它 运行 在您的终端上“pip install pillow”:

from PIL import Image
import io

image_data = ... # byte values of the image
image = Image.open(io.BytesIO(image_data))
print(f'{image.height}, {image.width}')