PHP CMYK to sRGB - JPG Images not keeping true colors

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

Hi all,

I've been trying to convert CMYK images from a PDF to sRGB for web display (since they're smaller). I get perfect color rendering when the output is CMYK, but when using sRGB colorspace ($img->setImageColorspace(Imagick::COLORSPACE_SRGB)) I do not get true colors. Essentially, everything brighter and more "Neon-y".

I've tried tons of combinations of code samples and none have solved the problem. I've download and tried a number of color profiles and that has not worked either.

If I open the CMYK jpg and change the color profile to RGB in photoshop, the result is perfect. However, I need to use Imagick for a workflow system that will convert numerous pages of out.

Can anyone help me understand what is going on and how to solve the problem. I've attached the good CMYK and my RGB output
Attachments
this is correct, converted to RGB in photoshop
this is correct, converted to RGB in photoshop
EvilErnie_04_Page_08-copy.jpg (456.34 KiB) Viewed 15163 times
this is what I get using imagick
this is what I get using imagick
EvilErnie_04_Page_08.jpg (354.24 KiB) Viewed 15163 times
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by fmw42 »

set the colorspace to sRGB before reading the input image -- at least that is what is done in command line.
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

I changed my code to this:

$img = new imagick();
$img->setResolution(300, 300);
$img->setImageColorspace(Imagick::COLORSPACE_SRGB);
$img->readImage($file_name);

and I get this:

Can not process empty Imagick object

It seems to only work after I read the images in
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

I even attempted to run my code to change the exported CMYK jpgs to RGB using Imagemagick on the command line (setting color space to RGB) and the output is exactly the same as if I run my php code.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by fmw42 »

I am not an Imagick expert. But you can try to use profiles to do the colorspace change.
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

Already tried that many times with many profiles. Also, tried creating my own CMYK jpg and using commandline to change it to RGB and the color changed just like before. Ill play around with the profiles so more but this seems to be a fundamental problem with how Imagemagick is transposing CMYK colors to the RGB scheme. Believe me, I know nothing about graphics so this is my best guess. I'm a coder by trade.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by fmw42 »

Perhaps you should extract the actual image from the PDF first, then change colorspace. IM cannot do that, but there are tools that can. See http://www.imagemagick.org/Usage/formats/#ps. Also if you post your pdf original, some one can test converting it in command line (or you can do that). Then just use PHP exec() to do the processing rather than Imagick. Imagick does not have the full functionality as Imagemagick and Imagick does not seem to be maintained very well.
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

I've been thinking of migrating to the PHP exec() formatted code but I have everything written the other way. I'll play around with it. Also, I'll see about getting my PDF posted.

question: do you know how I can install and confirm the installation of LCMS. I'm getting the impression that could be part of my problem as well.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by fmw42 »

I am on a Mac. So I just use MacPorts to install all my delegates, then install IM from source. I do not know how to link it to Imagick (if that is needed?)

Try the command line (in exec if you do not have terminal access) and see if your command works. If not, then you may have a missing delegate (LCMS?). Be sure to use LCMS 2.

convert -version will tell you if you have lcms installed.

convert -versions
Version: ImageMagick 6.9.1-7 Q16 x86_64 2015-07-05 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

I have Mac OS as well. When I run convert -list configure | grep -i "delegates", I see

DELEGATES bzlib mpeg freetype jng jpeg lzma png tiff xml zlib

However, LCMS 2 is definitely installed.
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

Doing what you suggested:

convert -versions
Version: ImageMagick 6.9.1-7 Q16 x86_64 2015-07-06 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by fmw42 »

IM is not seeing it. How did you install IM?

convert -list configure | grep -i "delegates"
DELEGATES bzlib mpeg fftw fontconfig freetype gslib jbig jng jpeg lcms lqr lzma openexr openjp2 png ps rsvg tiff webp x xml zlib

See my post at viewtopic.php?f=1&t=21502&p=88202&hilit ... rts#p88202, if you want to use MacPorts for your delegates and install IM manually from source.
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

I've always done everything with homebrew. I just uninstalled and reinstalled IM with Little-cms. Same problem. Ill give your suggestion a try!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by fmw42 »

Try with LCMS 2. Also are you installing IM from Homebrew or from source? If the former, you may need to install IM and LCMS together. Sorry, I do not know Homebrew.
gweiss27
Posts: 12
Joined: 2015-07-06T13:46:15-07:00
Authentication code: 1151

Re: PHP CMYK to sRGB - JPG Images not keeping true colors

Post by gweiss27 »

I'm doing it from homebrew. And I keep trying to uninstall and reinstall IM with LCMS2 but even though it appears to work, the delegates never update.
Post Reply