Search code examples
pythonnumpypython-imaging-libraryscikit-image

Information about image


How can I get the information about image? I need file size (bytes), image size (pixels), color mode, bits per pixel. I've already found image size (pixels) but I can't find another.

I have:

from skimage.io import imread

im = imread('abc.png')
print("Size: ", im.size, im.shape)

Solution

  • I recommend using the Pillow library.

    This will give you all the requested information about the image except the file size.

    from PIL import Image
    
    im = Image.open('whatever.png')
    width, height = im.size
    

    Refer to this link for the attributes for the image object

    In order to get the file size use this snippet below.

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