note 107716 modified in imagick.setimagecolorspace by danbrown

From: 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&#39;t forget to download the .icc files online): &#13;&#10;&#13;&#10;&#60;?php &#13;&#10;// don&#39;t use this (it inverts the image) &#13;&#10;// $img-&#62;setImageColorspace (imagick::COLORSPACE_RGB); &#13;&#10;&#13;&#10;if ($img-&#62;getImageColorspace() == Imagick::COLORSPACE_CMYK) { &#13;&#10; $profiles = $img-&#62;getImageProfiles(&#39;*&#39;, false); &#13;&#10; // we&#39;re only interested if ICC profile(s) exist &#13;&#10; $has_icc_profile = (array_search(&#39;icc&#39;, $profiles) !== false); &#13;&#10; // if it doesnt have a CMYK ICC profile, we add one &#13;&#10; if ($has_icc_profile === false) { &#13;&#10; $icc_cmyk = file_get_contents(dirname(__FILE__).&#39;/USWebUncoated.icc&#39;); &#13;&#10; $img-&#62;profileImage(&#39;icc&#39;, $icc_cmyk); &#13;&#10; unset($icc_cmyk); &#13;&#10; } &#13;&#10; // then we add an RGB profile &#13;&#10; $icc_rgb = file_get_contents(dirname(__FILE__).&#39;/sRGB_v4_ICC_preference.icc&#39;); &#13;&#10; $img-&#62;profileImage(&#39;icc&#39;, $icc_rgb); &#13;&#10; unset($icc_rgb); &#13;&#10;} &#13;&#10;&#13;&#10;$img-&#62;stripImage (); // this will drop down the size of the image dramatically (removes all profiles) &#13;&#10;?&#62; --was-- When converting from CMYK to RGB using this function, the image can become inverted. To fix this, use a workaround (don&#39;t forget to download the .icc files online): <?php // don&#39;t use this (it inverts the image) // $img->setImageColorspace (imagick::COLORSPACE_RGB); if ($img->getImageColorspace() == Imagick::COLORSPACE_CMYK) { $profiles = $img->getImageProfiles(&#39;*&#39;, false); // we&#39;re only interested if ICC profile(s) exist $has_icc_profile = (array_search(&#39;icc&#39;, $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__).&#39;/USWebUncoated.icc&#39;); $img->profileImage(&#39;icc&#39;, $icc_cmyk); unset($icc_cmyk); } // then we add an RGB profile $icc_rgb = file_get_contents(dirname(__FILE__).&#39;/sRGB_v4_ICC_preference.icc&#39;); $img->profileImage(&#39;icc&#39;, $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

« previous php.notes (#187779) next »