I'm using Pillow for image processing in Python,
url="http://www.image.com/some_image.jpg";path = io.BytesIO(urllib.request.urlopen(url).read())original_image = Image.open(path)
Any idea how i can get the size of this image file using Pillow? I'd like to process the image for size before storing it to disk
The answer is going to depend on what format you save the image in, so the most accurate solution would be along the lines of:
>>> out = io.BytesIO()
>>> original_image.save(out, format='png')
>>> out.tell()
# size in bytes
If you want the size of the uncompressed pixel data, you need to know how many bits are in a pixel. I don't believe this is exposed in Pillow, you'll have to lookup that value using original_image.mode
and reference Unpack.c. Then its just width * height * bytes_per_pixel
. If your image uses a palette, it gets more complicated and I'd recommend just using the first method.