PIL/Pillow decode icc profile information

I know this issue has been solved already, but I'm just adding this because it might be of some use to people who are looking for a way to extract ICC profile information in Python.

As part of the jpylyzer software (of which I'm the main developer), I once wrote some Python code for extracting the main header fields of an ICC profile (this is completely independent of any external libraries). See the validate_icc function below:

https://github.com/openpreserve/jpylyzer/blob/master/jpylyzer/boxvalidator.py#L598

If you follow this link and then scroll down a bit, you'll see an overview of all the reported properties. Note that the code does not actually read the information inside the ICC tags, but you could extend it based on the ICC profile specifications.


I am not aware of a dedicated Python module that can handle ICC color profiles.

If you feel adventurous, take a look at section 6 "Requirements" of the ICC Profile Format Specification. This should get you started on how to interpret the bytes.

Pillow's test folder contains two ICC profiles though, so perhaps it is worthwhile digging through the code of some of their tests. You might also want to look at this answer which refers to Little CMS that seems to have some ICC profile support.


I'm writing this also for people that came here searching for information on how to process ICC color profile information in Python.

The Pillow fork of the original PIL library for Python includes a ImageCms module. Unfortunately the constructor for a profile requires a filename or a file-like object, so we have to do it sideways via io.BytesIO

import io

from PIL import Image
from PIL import ImageCms

image = Image.open('/tmp/DQ-Tool_Print_13x18cm.jpg')
icc = image.info.get('icc_profile')
f = io.BytesIO(icc)
prf = ImageCms.ImageCmsProfile(f)

Now prf contains a color profile instance. Have a look at the docs here: https://pillow.readthedocs.io/en/stable/reference/ImageCms.html#PIL.ImageCms.CmsProfile