How to get image size in KB while using Pillow-python before storing to disk? -
i'm using pillow 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 can size of image file using pillow? i'd process image size before storing disk
the answer going depend on format save image in, accurate solution along lines of:
>>> out = io.bytesio() >>> original_image.save(out, format='png') >>> out.tell() # size in bytes
if want size of uncompressed pixel data, need know how many bits in pixel. don't believe exposed in pillow, you'll have lookup value using original_image.mode
, reference unpack.c. width * height * bytes_per_pixel
. if image uses palette, gets more complicated , i'd recommend using first method.
Comments
Post a Comment