I'm trying to convert RGB images to CMYK, because they need to be printed. I'm using this code:
<?php
$filePath = 'rgb.jpg';
// First save image as png
$image = new Imagick($filePath);
$image->setImageCompression(Imagick::COMPRESSION_UNDEFINED);
$image->setImageCompressionQuality(0);
$image->setImageFormat("png");
$filePath = 'rgb.png';
$image->writeImage($filePath);
$image->clear();
$image->destroy();
$image = null;
// Convert colors
$image = new Imagick($filePath);
$image->stripImage();
$image->setImageColorspace(Imagick::COLORSPACE_CMYK);
$image->setImageCompression(Imagick::COMPRESSION_UNDEFINED);
$image->setImageCompressionQuality(0);
$image->setImageFormat("png");
$filePath = 'cmyk.png';
$image->writeImage($filePath);
$image->clear();
$image->destroy();
$image = null;
$fileUrl = 'http://www.product-designer.nl/rgb2cmyk/cmyk.png';
?>
CMYK Image:<br/>
<img src="<?php echo $fileUrl; ?>" width="400" /><br /><br />
<?php
$fileUrl = 'http://www.product-designer.nl/rgb2cmyk/rgb.png';
?>
RGB Image:<br/>
<img src="<?php echo $fileUrl ?>" width="400" />
You can see the result on http://product-designer.nl/rgb2cmyk I don't know how, but somehow the colors on the image become inverted. I need to convert the image but the colors need to be as close to the RGB colors as possible.
Does anyone know how to do this?
Thanks