Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imagemagick convert CMYK pdf to RGB jpeg or PNG and preseerve colors

I have a cmyk pdf that I am trying to convert to a RGB jpeg or png file but have the colors stay pretty close to what the CMYK version is (compared to how photoshop does it)

I am trying the following command but the colors change drastically from a red color to almost bright neon red and so on.

Here is the command

 convert cmykpdf.pdf +profile icc -profile AdobeRGB1998.icc -colorspace sRGB jpegtesting.jpg

Any ideas? or thoughts on how to do this. I tried saving it as a PNG also and same issue occurs and have tried changing sRGB to just RGB

NOTE: It doesnt necessarily need to be RGB jpeg it can even be CMYK jpeg but i just need it to be displayed in the browser correctly and I know safari does not display cmyk jpegs correctly

My goal is to just display a img in the browser that shows the correct color and correct resolution nothing pixilated

like image 804
Yeak Avatar asked Aug 14 '13 22:08

Yeak


2 Answers

The solution is fairly easy, there's nothing voodoo or special about Photoshop's CMYK to RGB nowadays. Imagemagick uses LCMS color engine, which does its job just fine.

But first you'll need to edit delegates.xml file inside IM's directory. Find the line with delegate decode="ps:cmyk" and insert -dUseCIEColor=false near the end, so it looks like that:

<delegate decode="ps:cmyk" restrain="True" command="&quot;@PSDelegate@&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pamcmyk32&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; -dUseCIEColor=false &quot;-f%s&quot; &quot;-f%s&quot;"/>

It's necessary because otherwise Ghostscript (before returning pam image to ImageMagick) will perform CMYK to CMYK convertion (assuming DeviceCMYK to be CIEbased CMYK), and you probably don't want that, as colors will shift considerably.

Then try this command:

convert -density 144 cmyk.pdf -profile USWebCoatedSWOP.icc -resample 72 -profile "sRGB Color Space Profile.icm" -quality 100 out.jpg

Here we take cmyk.pdf (rather, temporary pam image that GS returns to IM), assign CMYK profile (just as you do in Photoshop, when you open a file or do it explicitly - therefore choose profile that describes you input CMYK best), convert it to sRGB profile (because I don't think you want AdobeRGB as color space of images for Internet) and save to jpeg. Reduce quality parameter as needed.

One more trick here is additional manual anti-aliasing -- note intermediate resolution of 144 dpi and final 72 dpi. Because I don't think that Ghostscript's anti-aliasing with -dGraphicsAlphaBits=4 is en par with Photoshop's anti-aliasing.

The result of this command looks exactly the same as converted in Photoshop.

like image 182
user2846289 Avatar answered Nov 16 '22 02:11

user2846289


You could try this:

convert -negate -colorspace RGB srcfile.jpg outputfile.jpg

Let me know if it works!

like image 4
Mackelito Avatar answered Nov 16 '22 00:11

Mackelito