IM produces CMYK JPG that Finder/preview opens incorrectly

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
Monarobase
Posts: 4
Joined: 2010-06-25T06:26:13-07:00
Authentication code: 8675308

IM produces CMYK JPG that Finder/preview opens incorrectly

Post by Monarobase »

Hello,

I'm in the process of developing a PHP script to create CMYK PDF'S and I need to convert JPEG files to CMYK but have come across something strange and was wandering if you could give me some information about why this happens.

Here is my convert command :

Code: Select all

convert input.jpg  -profile cmyk.icc -colorspace CMYK output.jpg
When I convert a RVB JPEG file to CMYK with photoshop, with or without including a color profile I can see the correct colors in MacOSX Finder and Preview however when I do the same with ImageMagick with or without using '-strip' in the command the resulting image is mostly black in the finder, it opens fine in all adobe programs but not in the finder or preview.

I do not actually need the image to open correctly in the finder but am trying to work out why illustrator doesn't open PDF files that include CMYK images inserted by TCPDF correctly and for the first step I would like to understand what is so different between a CMYK JPEG file produced with ImageMagick and a CMYK JPEG file produced with Photoshop.

Thanks in advance.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by snibgo »

I would like to understand what is so different between a CMYK JPEG file produced with ImageMagick and a CMYK JPEG file produced with Photoshop.
This forum may not have many folk who can directly answer the question. But if you post URLs to a sample of each, someone might take a look at them.
snibgo's IM pages: im.snibgo.com
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by Drarakel »

A note regarding your command:
Monarobase wrote:

Code: Select all

convert input.jpg  -profile cmyk.icc -colorspace CMYK output.jpg
It seems that you are trying to do a conversion similar to Photoshop - i.e. a conversion with profiles - is that correct? Then this command won't always do that. If your input.jpg doesn't have an embedded color profile, then the conversion is done only with '-colorspace CMYK' (not as good as with profiles), and after that cmyk.icc gets embedded. You rather should use two profile parameters - one for the source profile (e.g. sRGB), the second for the destination profile. (If input.jpg has an embedded profile, then your former command is alright. You don't need the '-colorspace CMYK' though.)
See also here.

Regarding the different display of your images - I would also want to wait for sample files before I'm trying to answer...
When the display is not right - do the images look like inverted then?
Monarobase
Posts: 4
Joined: 2010-06-25T06:26:13-07:00
Authentication code: 8675308

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by Monarobase »

Hello again, sorry about the delay !

Yes the image looks inverted. I will try to post some screen shots asap.

As for the profiles, I will be try to remove the -colorspace CMYK and let you know about the result but I have already tried the opposite and got an inverted image :

I took a CMYK image converted with the previous command so it contains a CMYK profile a did this :

Code: Select all

convert inputcmyk.jpg  -profile srvb.icc outputrvb.jpg
I've got to do a series of tests though before asking you to help me out on this one to see if I cannot find the answer myself !
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by axelrose »

I can confirm this. Neither Apple's QuickView or Preview.app properly displays any CMYK JPEGs
created with current ImageMagick versions.

I just do

Code: Select all

convert logo: -profile rgb.icc -profile cmyk.icc -colorspace cmyk -strip logo.jpg
The output "logo.jpg" is ok. when checked in Photoshop but not in Finder or Preview.

exiftools shows those color specific entries in meta data:

Code: Select all

 <Adobe:DCTEncodeVersion>100</Adobe:DCTEncodeVersion>
 <Adobe:APP14Flags0>(none)</Adobe:APP14Flags0>
 <Adobe:APP14Flags1>(none)</Adobe:APP14Flags1>
 <Adobe:ColorTransform>Unknown (RGB or CMYK)</Adobe:ColorTransform>
Don't know, whether this is correct.

Cheers, Axel.
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by axelrose »

Out of curiosity I tried with an older IM 6.5.9-10.
The output there looks fine when viewed with Preview.app.

I contiue checking this later.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by anthony »

I would be careful about reading and writing JPEG images just to set profiles. JPEG is lossy, when ever you write it you loose some information. To just add a color profile I would look at a loss-less method such as programs like jhead.

If the profiles actually MODIFY the actual data (changing color profiles) than that is fine, Imagemagick can do this, but you need at least two color profiles to do the conversion, the first either supplied with the image, or provided using the first -profile option. You can also simply remove the color profile and then provide it directly too.

Once the image has a profile (part of image or set), then the next color -profile option will re-map the pixel values, to match.

You must remember that ImagMagick is a Image processor, which will almost always read in and write out the image data, for processing purposes.


Note also that -colorspace is just a way of specifying the gross storage of color values, and simple color conversions. It is not nearly as exact as using -profiles.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by fmw42 »

convert logo: -profile Profiles/sRGB.icc -profile Profiles/cmyk.icc -colorspace cmyk -strip logo1.jpg
This is not really good at best it is overkill. The first profile converts to RGB, the second converts it to CMYK, the -colorspace tries to convert to CMYK again, the -strip removes the two first profiles.

This is adequate
convert logo: -colorspace cmyk logo2.jpg

or this

convert logo: -profile Profiles/sRGB.icc -profile Profiles/CMYK.icc logo3.jpg


However, for images with a cmyk profile, you need do nothing or add -strip at the beginning and then just do -colorspace

convert logo: -strip -colorspace CMYK logo4.jpg

or do -strip and add your own profile

convert logo: -strip -profile Profiles/sRGB.icc -profile Profiles/CMYK.icc logo5.jpg

HOWEVER, this is all a problem with Mac PREVIEW. If you display in Firefox, it looks just fine. Mac Preview and Safari (at least on my Tiger system) have had this problem with cmyk jpgs for as long as I know.
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by axelrose »

Thanks for keeping the topic alive.

Apple Preview seems to have a problem with CMYK JPEG. I tried again using different approaches like this:

Code: Select all

cd /tmp
rm -f logo-rgb.jpg logo-sips-cmyk.jpg logo-im-cmyk.jpg logo-psd-cmyk.jpg

convert logo: -profile rgb.icm logo-rgb.jpg

sips -m cmyk.icc logo-rgb.jpg --out logo-sips-cmyk.jpg
exiftool -ColorTransform logo-cmyk.jpg

convert logo-rgb.jpg -profile rgb.icm -profile cmyk.icc logo-im-cmyk.jpg
exiftool -ColorTransform logo-im-cmyk.jpg

# open "logo-rgb.jpg" in Photoshop and convert into profile "cmyk.icc", save as "logo-psd-cmyk.jpg"
exiftool -ColorTransform logo-psd-cmyk.jpg
The results Image
show that even CMYK JPEG produced with Apple's own "sips" isn't displayed properly
(though I'm not sure whether my usage of "sips" is correct)

But why is the result saved by Photoshop ok? I will try to investigate this further by
copying attribute by attribute from "logo-psd-cmyk.jpg" into "logo-im-cmyk.jpg" and
watching when Preview shows the desired result.

Regards, Axel.
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by axelrose »

It seems that Preview works fine if it finds Photoshop tags.
If I patch the IM produced CMYK JPEG with exiftool:

Code: Select all

cp logo-im-cmyk.jpg logo-im-patched.jpg
exiftool -tagsfromfile logo-psd-cmyk.jpg -photoshop:all logo-im-patched.jpg
Preview is displaying the result as expected.

Could I add the Photoshop profile during a "convert" command sequence?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by fmw42 »

That is an interesting result and workaround. However, as I said above this is really a Preview issue as Firefox display's the image properly.

Nevertheless, IM can read, but I don't know if it can write EXIF tags. See http://www.imagemagick.org/script/escape.php

This page seems to imply that you can write some profile information. See http://www.imagemagick.org/Usage/formats/#profiles

Exiftool is the general tool of choice for doing that if IM currently cannot.

Perhaps you should bring this up on the Developers forum. Some one there may have more information.

Keep us posted if you find a good method to correct cmyk jpgs for display in PREVIEW/Safari etc.

P.S. Others have told me that they don't see this problem on Mac Snow Leopard/INTEL hardware. My old Mac is Tiger/PowerPC
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: IM produces CMYK JPG that Finder/preview opens incorrect

Post by axelrose »

same problem with Snow Leopard and Intel CPU
Post Reply