Page 1 of 1

Colour profiles in php Imagick

Posted: 2013-04-22T07:45:41-07:00
by sudoku
I need to convert various rgb files inte sRGB. As quality matters, I use color profiles.

Until now I use the commandline convert in my PHP script:

Code: Select all

convert 'anyRGBfile.jpg' -profile '$sRGBprofil' 'sRGBfile.jpg'
This works exact in the way I want: If there is a profile in the source file included, the file is correctly converted to srgb. If the source contains no profile, it is treated as if it contained a sRGB-profile.

Now I tried to do the same thing using the Imagick class - without success:

Code: Select all

		
$source='Desert-eci-rgb.jpg';
$sRGBprofil="sRGB_IEC61966-2-1.icc"; 

$image=new Imagick($source);
$profiles = $image->getImageProfiles('*', false); // get profiles
$has_icc_profile = (array_search('icc', $profiles) !== false);

if ($has_icc_profile === false)
{
  // image does not have a ICC profile, we add one
  $icc_in = file_get_contents('$sRGBprofil');
  $image->profileImage('icc', $icc_in);
}

// Destination rgb profile
$icc_out = file_get_contents('$sRGBprofil');
$image->profileImage('icc', $icc_out);

header( "Content-Type: image/jpeg" );
echo $image;
This code works fine, if there is no profile included. Otherwise the iembedded profile is just ignored.
Can anyone give me a hint, please?

Thanks in advance