[Image-SIG] Embedded ICC profiles

Florian Höch lists+Image_SIG at hoech.org
Sat Feb 23 01:13:00 CET 2008

Just a quick follow-up regarding PNG and reading embedded profiles with 
PIL in general: I looked at PIL's PngImagePlugin.py and found that 
support to read embedded ICC profiles was not there. So I added a method 
to be able to retrieve the profile:

PngImagePlugin.py, line 35:
import zlib

PngImagePlugin.py, line 165:
class PngStream(ChunkStream)
     def chunk_iCCP(self, pos, len):
         # ICC profile
         s = ImageFile._safe_read(self.fp, len)
         # according to PNG spec, the iCCP chunk contains:
         # Profile name 	1-79 bytes (character string)
         # Null separator 	1 byte (null character)
         # Compression method 	1 byte (0)
         # Compressed profile 	n bytes (zlib with deflate compression)
         i = string.find(s, chr(0))
         self.im_info["icc_profile"] = zlib.decompress(s[i+2:])
         return s

Then, the profile data can be accessed via im.info["icc_profile"]

Here's the additions necessary to also have im.info["icc_profile"] 
entries for JPEG and TIFF:

JpegImagePlugin.py, line 85 in def APP(self, marker):
     elif marker == 0xFFE2 and s[:12] == "ICC_PROFILE\0": # ICC profile
         self.info["icc_profile"] = s[14:]

TiffImagePlugin.py, line 105:

TiffImagePlugin.py, line 519 in def _decoder(self, rawmode, layer):
         if self.tag.has_key(ICCPROFILE):
             self.info['icc_profile'] = self.tag[ICCPROFILE]



More information about the Image-SIG mailing list