Page 1 of 1

How to handle invalid color profiles

Posted: 2019-08-01T11:22:53-07:00
by ikerr
The image in a previous forum post has RGB pixels but a CMYK color profile:

http://www.imagemagick.org/discourse-se ... hp?t=30217

When I attempt to convert this file using the following command, the output file has heavily distorted colors, presumably because ImageMagick is attempting to use the CMYK profile, even though the image is RGB:

Code: Select all

convert fXBUFte.jpg -profile sRGB2014.icc out.jpg
However, if I strip the CMYK profile (e.g., using -strip), I get a reasonable result:

Code: Select all

convert fXBUFte.jpg -strip -profile sRGB2014.icc out.jpg
From the same forum post linked to above, it looks like ImageMagick used to output the following error when a profile did not match the pixel format:

Code: Select all

color profile operates on another colorspace `icc' @ error/profile.c/ProfileImage/1047
Without this error, I'm not sure how I can check for compatibility between the pixel format and the embedded profile, in an automated and robust way. Is there some other way to check for compatibility, or should this error be reintroduced?

I'm using ImageMagick 7.0.8-25 Q16 x86_64 2019-02-01.

Re: How to handle invalid color profiles

Posted: 2019-08-01T12:02:27-07:00
by snibgo
I suppose it depends on what you want to test for. In this case, the image has 3 channels but the ICC is for 4 channels. This is technically valid, but we might say it suggests a problem.

IM can read the image and write a profile. exiftool can tell us the profile has 4 channels.