Search code examples
pythonimagebytesize

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


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


Solution

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