How to get image size (bytes) using PIL

Abdelouahab Pp picture Abdelouahab Pp · Aug 10, 2012 · Viewed 34.9k times · Source

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.

Answer

thebjorn picture thebjorn · Aug 10, 2012

Try:

import os
print os.stat('somefile.ext').st_size