possible bug PHP JPG CMYK to RGB conversion
Posted: 2013-10-03T01:08:37-07:00
hi
I have found possible bug in ImageMagick 6.8.6-3 2013-09-09 Q16 PHP version
most of the files (especially PSD files) convert without any problems but there's sometimes problem with JPG files
(original CMYK on the left and RGB after conversion on the right):
conversion PHP script
the file with problems for testing can be dowloaded from: http://tulipano.pl/imagicktest.jpg
I have found possible bug in ImageMagick 6.8.6-3 2013-09-09 Q16 PHP version
most of the files (especially PSD files) convert without any problems but there's sometimes problem with JPG files
(original CMYK on the left and RGB after conversion on the right):
conversion PHP script
Code: Select all
$image = new Imagick('test file.jpg');
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
echo "converting from CMYK / <br>";
$profiles = $image->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('USWebUncoated.icc');
if ($image->profileImage('icc', $icc_cmyk)) { echo "cmyk profile added <br>"; }
//$image->writeImage("test file cmyk2.jpg");
unset($icc_cmyk);
}
// then we add an RGB profile
//$icc_rgb = file_get_contents('sRGB_v4_ICC_preference.icc');
$icc_rgb = file_get_contents('AdobeRGB1998.icc');
if ($image->profileImage('icc', $icc_rgb)) { echo "rgb profile added <br>"; }
if ($image->setImageColorSpace(Imagick::COLORSPACE_RGB)) { echo "colorspace set to rgb <br>"; }
unset($icc_rgb);
$php_vs_arr = preg_split("/\./", phpversion());
$php_vs = $php_vs_arr[0] . '.' . $php_vs_arr[1];
//fix gamma, hue, saturation, brightness
if($php_vs < 5.3) {
echo "<5.3";
//ADJUST GAMMA BY 20% for 5.2.x
$range = $image->getQuantumRange();
$image->levelImage(0, 2.0, $range['quantumRangeString']);
} else {
echo ">5.3";
//php 5.3 hack FOR INVERTED COLORS
$image->negateImage(false, Imagick::CHANNEL_ALL);
}
}
$image->writeImage("test file rgb.jpg");