How to get image size (bytes) using PIL

前端 未结 5 1894
清歌不尽
清歌不尽 2020-12-18 18:20

I found out how to use PIL to get the image dimensions, but not the file size in bytes. I need to know the file size to decide if the file is too big to be uploaded to the d

5条回答
  •  难免孤独
    2020-12-18 18:58

    To find the Size(In bytes) of an image using Pillow Library, please use the below code. It will working fine.

    from PIL import Image
    image_file = Image.open(filename)
    print("File Size In Bytes:- "+str(len(image_file.fp.read()))
    

    Make sure that you have pillow library installed:-

    pip install pillow
    

提交回复
热议问题