How to handle invalid color profiles

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ikerr
Posts: 1
Joined: 2019-08-01T11:07:42-07:00
Authentication code: 1152

How to handle invalid color profiles

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to handle invalid color profiles

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply