Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2020-11-26 13:53:02

i want to know if there some way to get the size and resolution of the image that already in bytes in python, i tried to search about it and it was using an external library.. did you know how to do it by external libraries or not.

thanks

Questioner
Fahmi Roihan
Viewed
0
ozs 2020-11-29 03:25:42

you can use PIL (pillow).

to install it run "pip install pillow" on your terminal:

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