How to get image size (bytes) using PIL
问题 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. 回答1: Try: import os print os.stat('somefile.ext').st_size 回答2: If you already have the image on the filesystem: import os os.path.getsize('path_to_file.jpg')` If, however, you want to get the saved size of an image that is in memory and has not been saved to the filesystem: from io import BytesIO img_file =