I am not much of an image compression guru but I am looking for the image depth. The Python snippet below shows an image depth of 8 but other (more reliable) methods indicate that the depth is actually 32.
url="http://lesschwab.com/images/product-wizard-ad-tires.png"
width=177, height=177, depth=8, type=truecolormatte, colorspace=srgb
I suspect a multiplier based on number of channels or colorspace or something else. How do I find or calculate the actual image depth?
#!/usr/bin/env python
from __future__ import print_function
import sys
import requests
from wand.image import Image
def main():
url = 'http://lesschwab.com/images/product-wizard-ad-tires.png'
resp = requests.get(url, timeout=5.0, headers={'User-agent': 'Mozilla/4.0'})
if resp.status_code == 200:
try:
with Image(blob=resp.content) as img:
print ('url="%s"' % url)
print('width=%d, height=%d, depth=%d, type=%s, colorspace=%s' %
(img.width, img.height, img.depth, img.type,
img.colorspace))
except Exception as ex:
print('Unable to decode this image (%d bytes) format.' %
len(resp.content), str(ex))
if __name__ == '__main__':
sys.exit(main())
EDIT: Additional info:
I am using the same py code to read every possible image type that may arise on the web so I have to do this pro-grammatically. For this particular image I can see the values of 8 in img.channel_depths['red'], img.channel_depths['green'], img.channel_depths['blue'] & img.channel_depths['alpha'] but there are 15 more channel depth keys and they all have values. I am guessing that a colorspace of 'sRGB' implies a mapping to the alpha, red, green & blue channel depths. Unfortunately there seems to be 34 possibilities for colorspace types:
('undefined', 'rgb', 'gray', 'transparent', 'ohta',
'lab', 'xyz', 'ycbcr', 'ycc', 'yiq', 'ypbpr', 'yuv', 'cmyk',
'srgb', 'hsb', 'hsl', 'hwb', 'rec601luma', 'rec601ycbcr',
'rec709luma', 'rec709ycbcr', 'log', 'cmy', 'luv', 'hcl',
'lch', 'lms', 'lchab', 'lchuv', 'scrgb', 'hsi', 'hsv',
'hclp', 'ydbdr')
and 19 possible channel depth keys:
['opacity', 'true_alpha', 'gray', 'rgb_channels',
'yellow', 'sync_channels', 'default_channels', 'alpha',
'cyan', 'magenta', 'undefined', 'blue', 'index',
'gray_channels', 'composite_channels', 'green',
'all_channels', 'black', 'red']
I am hoping find a mapping table between the compression type/colorspace and their associated channel depths (or maybe just a depth multiplier for each colorspace).