note 107716 modified in imagick.setimagecolorspace by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:12:15 +0000 |
| Subject: | note 107716 modified in imagick.setimagecolorspace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187779@lists.php.net to get a copy of this message | ||
When converting from CMYK to RGB using this function, the image can become inverted. To fix this,
use a workaround (don't forget to download the .icc files online):
<?php // don't use this (it
inverts the image) // $img->setImageColorspace
(imagick::COLORSPACE_RGB); if
($img->getImageColorspace() == Imagick::COLORSPACE_CMYK) { $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_cmyk =
file_get_contents(dirname(__FILE__).'/USWebUncoated.icc');
$img->profileImage('icc', $icc_cmyk);
unset($icc_cmyk); } // then we add an RGB profile
$icc_rgb =
file_get_contents(dirname(__FILE__).'/sRGB_v4_ICC_preference.icc');
$img->profileImage('icc', $icc_rgb);
unset($icc_rgb); } $img->stripImage
(); // this will drop down the size of the image dramatically (removes all profiles)
?>
--was--
When converting from CMYK to RGB using this function, the image can become inverted. To fix this,
use a workaround (don't forget to download the .icc files online):
<?php
// don't use this (it inverts the image)
// $img->setImageColorspace (imagick::COLORSPACE_RGB);
if ($img->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
$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_cmyk = file_get_contents(dirname(__FILE__).'/USWebUncoated.icc');
$img->profileImage('icc', $icc_cmyk);
unset($icc_cmyk);
}
// then we add an RGB profile
$icc_rgb = file_get_contents(dirname(__FILE__).'/sRGB_v4_ICC_preference.icc');
$img->profileImage('icc', $icc_rgb);
unset($icc_rgb);
}
$img->stripImage (); // this will drop down the size of the image dramatically (removes all
profiles)
?>
http://php.net/manual/en/imagick.setimagecolorspace.php