As already mentioned in this question, by using Pillow
you can do the following:
from PIL import Image
im = Image.open('image.jpg', 'r')
If successful, this function returns an Image object. You can now use instance attributes to examine the file contents:
width, height = im.size
pixel_values = list(im.getdata())
print(im.format, im.size, im.mode)
The format
attribute identifies the source of an image. If the image was not read from a file, it is set to None. The mode
attribute defines the number and names of the bands in the image, and also the pixel type and depth. Common modes are “L” (luminance) for greyscale images, “RGB” for true color images, and “CMYK” for pre-press images.