Reputation: 11302
I am having such a hard time trying out to convert images from Adobe RGB to sRGB profile that now I start to think maybe I can't assign or convert color profiles at all on my host.
ImageMagick 6.8.9-6 Q16 x86_64 2014-08-15
class_exists("Imagick") = true
Here I try to assign the profile to an image created with IM, even that does not work.. What is wrong here?
try {
$image = new Imagick();
$image->newImage(100, 100, new ImagickPixel('red'));
$image->setImageFormat('jpg');
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(60);
// TRY 1
// $image->setImageColorspace(Imagick::COLORSPACE_SRGB);
// TRY 2
$profile_path = "sRGB_IEC61966-2-1_black_scaled.icc";
$profile = file_get_contents($profile_path);
$image->profileImage("icc", $profile);
$image->setImageColorspace(Imagick::COLORSPACE_SRGB);
} catch(Exception $e) {
echo 'Exception caught: ', $e->getMessage(), "\n";
}
header("Content-Type: image/jpg");
echo $image->getImageBlob();
EDIT Here is what I tried with an existing image with the Adobe RGB color space:
try {
$profile_path = "sRGB_IEC61966-2-1_black_scaled.icc";
$image = new Imagick();
$image->readImage("original-small.jpg");
// TRY 1 > keeps the same Adobe RGB profile
// $image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
// TRY 2 > strips all EXIF data + profile but does NOT assign new profile
// $image->stripImage();
// $image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
// TRY 3 > keeps the same Adobe RGB profile
// $profile = file_get_contents($profile_path);
// $image->profileImage("icc", $profile);
// $image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
// TRY 4 > strips all EXIF data + profile but does NOT assign new profile
// $image->stripImage();
// $profile = file_get_contents($profile_path);
// $image->profileImage("icc", $profile);
// $image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
} catch(Exception $e) {
echo 'Exception caught: ', $e->getMessage(), "\n";
}
header("Content-Type: image/jpg");
echo $image->getImageBlob();
Upvotes: 2
Views: 2607
Reputation: 25721
I misread what you were asking. The code below changes an image from having being an Adobe style color profile to being a 'normal' web one.
$image = new Imagick("fullSize_MK3L7748.jpg");
// This isn't required - but it could be used
// $image->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$profile = file_get_contents("sRGB_IEC61966-2-1_black_scaled.icc");
$image->profileImage("icc", $profile);
$image->writeImage("test_blackScaled.jpg");
Checking the images with identify now gives:
# identify -verbose fullSize_MK3L7748.jpg | grep icc
icc:name: Adobe RGB (1998)
Profile-icc: 560 bytes
and
# identify -verbose test_blackScaled.jpg | grep icc
icc:name: IEC 61966-2-1 Default RGB Colour Space - sRGB
Profile-icc: 3048 bytes
And the images should look almost the same - exact results may vary per browser.
Source image in aRGB
Output image
Upvotes: 0