How can I get the depth of a jpg file?

I want to get the bit depth for a jpeg file using Python.

Using Python Image Library:

import Image
data = Image.open('file.jpg')
print data.depth

However, this gives me a depth of 8 for a 24-bit image. Am I doing something wrong? Is there a way to do this with pure Python code?

Thanks in advance.

Edit: this is data.bits not data.depth.

+8
source share
4 answers

I do not see the attribute depthdocumented anywhere in the Python Image Library Reference . However, it seems that only a limited number of modes are supported . You can use something like this:

mode_to_bpp = {'1':1, 'L':8, 'P':8, 'RGB':24, 'RGBA':32, 'CMYK':32, 'YCbCr':24, 'I':32, 'F':32}

data = Image.open('file.jpg')
bpp = mode_to_bpp[data.mode]
+12

Jpeg , GIF PNG. , Jpeg, .

+7

PIL "". depth PIL, , , :

data.depth * len(data.getbands())

:

data.mode

. .

+3

, JPG 24- . 8- , , , 24 . , , :

If you use a more modern version of Photoshop, you will notice that it will also allow you to work with 16 bits per channel, which gives you 48 bits per pixel.

But I can’t find a link to how you could distinguish them from each other.

+2
source

All Articles