RGB to CMYK inverted colors (script PHP)

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
Panda
Posts: 3
Joined: 2013-08-27T03:03:57-07:00
Authentication code: 6789

RGB to CMYK inverted colors (script PHP)

Post by Panda »

I am trying to convert a RGB photo in CMYK with a php script.

but inverted colors (O_O)

Image

looking on google ..
http://stackoverflow.com/questions/4830 ... yk-inverts

is a bug or script wrong ?

SCRIPT PHP

Code: Select all

$filePath = $percorso."/".$dir_letta."/".$file_letto;
								$i = new Imagick($filePath);
								 
								$cs = $i->getImageColorspace();
								
								
								if ($cs == Imagick::COLORSPACE_SRGB || 
									$cs == Imagick::COLORSPACE_RGB){
									print "Image is RGB<br/>\n";
																 
									?>
									RGB Image:<br/>
									<img src="<?php echo $filePath ?>"/>
									<br/><br/>
									<?php
								 
									$i->setImageColorspace(Imagick::COLORSPACE_CMYK);
									$i->setImageFormat('jpeg');
								 
								 	$pos_punto = strripos($file_letto,"."); //ultima posizione del punto
									$nomefile = substr($file_letto,0,$pos_punto); //nome file senza riferimento al tipo		
									
									echo "nomefile: ".$nomefile."<br>";
									
									// write it to a temp file
									$filePath = $percorso."/".$dir_letta."/".$nomefile."-pdf.jpg";
									$i->writeImage($filePath);
								 
								} else {
									print "Image is not RGB<br/>\n";
								}
								 
								if ($cs == Imagick::COLORSPACE_CMYK) {
								 
									print "Image is CMYK<br/>\n";
								}
								 
								?>
								CMYK Image:<br/>
								<img src="<?php echo $filePath ?>"/>
								<?php
								 
								$i->clear();
								$i->destroy();
								$i = null;


HOSTING - PHPINFO
imagick module version 3.0.1
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version ImageMagick 6.8.6-1 2013-06-24 Q16 http://www.imagemagick.org
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: RGB to CMYK inverted colors (script PHP)

Post by holden »

You probably should try using profiles http://forums.adobe.com/thread/285113 (This is just the first link I found, there must be hundreds more :) )

viewtopic.php?f=1&t=16572
Panda
Posts: 3
Joined: 2013-08-27T03:03:57-07:00
Authentication code: 6789

Re: RGB to CMYK inverted colors (script PHP)

Post by Panda »

I used icc profile


but... but the resulting image is brighter/overexposed..... why?

Image


Code: Select all

$img = new Imagick($filePath);
								
								$cs = $img->getImageColorspace();
								
								// don't use this (it inverts the image) 
								//    $img->setImageColorspace (imagick::COLORSPACE_RGB); 
								
								if ($cs == Imagick::COLORSPACE_SRGB || $cs == Imagick::COLORSPACE_RGB){
								   $profiles = $img->getImageProfiles('*', false); 
								   // we're only interested if ICC profile(s) exist 
								   $has_icc_profile = (array_search('icc', $profiles) !== false); 
								   // if it doesnt have a CMYK ICC profile, we add one 
								   if ($has_icc_profile === false) { 
									   $icc_rgb = file_get_contents('adminusers/script/AdobeICCProfiles/RGB Profiles/AppleRGB.icc'); 
									   $img->profileImage('icc', $icc_rgb); 
									   unset($icc_rgb); 
								   } 
								   // then we add an RGB profile 
								   $icc_cmyk = file_get_contents('adminusers/script/AdobeICCProfiles/CMYK Profiles/UncoatedFOGRA29.icc'); 
								   $img->profileImage('icc', $icc_cmyk); 
								   unset($icc_cmyk); 
								} 

$img->stripImage();
								
								
								$pos_punto = strripos($file_letto,"."); //ultima posizione del punto
								$nomefile = substr($file_letto,0,$pos_punto); //nome file senza riferimento al tipo		
								
								echo "nomefile: ".$nomefile."<br>";
								
								// write it to a temp file
								$filePath = $percorso."/".$dir_letta."/".$nomefile."-pdf.jpg";
								$img->writeImage($filePath);
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: RGB to CMYK inverted colors (script PHP)

Post by snibgo »

Can you put up your input file?
snibgo's IM pages: im.snibgo.com
Panda
Posts: 3
Joined: 2013-08-27T03:03:57-07:00
Authentication code: 6789

Re: RGB to CMYK inverted colors (script PHP)

Post by Panda »

snibgo wrote:Can you put up your input file?
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: RGB to CMYK inverted colors (script PHP)

Post by fmw42 »

JPG CMYK files often do not show correctly in many viewers unless you use a profile to convert to CMYK. Inverted colors is the symptom.

Your input has an odd profile === Profile-APP12: 15 bytes

So just convert to a CMYK profile via

convert qf9e.jpg -profile /Users/fred/images/profiles/USWebCoatedSWOP.icc qf9e_cmyk.jpg

That looks just fine to me compared to the input.

Oddly, if I remove all profiles via -strip or +profile, and apply an sRGB profile and then convert to CMYK profile, the result is still inverted. So that tells me that the Profile-APP12 is important in your input and that you do not have a simple sRGB input image.
Post Reply