How can I detect if the JPG is AdobeRGB and if it is convert it in python to sRGB JPG.
If that is possible in PIL, that would be great. Thank you.
To program this yourself, you could convert pixels in the AdobeRGB colorspace to CIE XYZ, and then convert that to sRGB. PIL image
objects have a method named convert()
with the ability to apply a general matrix transformation to all the pixels in an image (see the section on Image.convert() in the the online documentation of the PIL Image module -- note the example showing the matrix values needed for going from RGB to XYZ).
Section 4.3.4 in the AdobeRGB1998 .pdf spec shows a matrix for transforming XYZ into RGB.
I'm not sure how to detect the colorspace of JPG images. I recall reading something about ICC xml profiles being attached to the end of the file (and a problem arising when there was more than one), but I can't vouch for its validity. The Wikipedia article on the JPEG file format says profiles are embedded.