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.
I had the same problem, I tested all answers and get wrong color in final image. @DrMeers All matrixes I've tried gave wrong result in red and blacks, so here is my solution:
The only way I found out is to read profile from image and convert using ImageCms.
from PIL import Image
from PIL import ImageCms
import tempfile
def is_adobe_rgb(img):
return 'Adobe RGB' in img.info.get('icc_profile', '')
def adobe_to_srgb(img):
icc = tempfile.mkstemp(suffix='.icc')[1]
with open(icc, 'w') as f:
f.write(img.info.get('icc_profile'))
srgb = ImageCms.createProfile('sRGB')
img = ImageCms.profileToProfile(img, icc, srgb)
return img
img = Image.open('testimage.jpg')
if is_adobe_rgb(img):
img = adobe_to_srgb(img)
# then do all u want with image. crop, rotate, save etc.
I think this method can be used to any color profile, but not tested.