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 database.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Try:
If you already have the image on the filesystem:
If, however, you want to get the saved size of an image that is in memory and has not been saved to the filesystem:
This method will avoid multiple reads of the image data as with StringIO. Note, however, that it will use more RAM. Everything is a tradeoff. :-)
Edit: I just saw this comment from the OP:
This is a very different question, and is probably best accomplished at the web server. For nginx, you can add this to your configuration:
To find the Size(In bytes) of an image using Pillow Library, please use the below code. It will working fine.
Make sure that you have pillow library installed:-
I'm a bit late to this, but I came across this question 5 mins ago when searching how to get the size of a PIL image without saving it to disk. In case anyone else comes across this, this is a simple way of doing it:
I think this is the true measure and the fastest one of the size of the image in bytes in memory:
Then, the size of the file on disk depends on the format of the file:
Possible output for 32 x 32 x 3 images from CIFAR10 dataset: