想象:无法分配或转换颜色配置文件

时间:2015-04-24 12:23:48

标签: imagick color-profile

我正在努力将图像从Adobe RGB转换为sRGB配置文件,现在我开始认为我可以在主机上分配或转换颜色配置文件。

ImageMagick 6.8.9-6 Q16 x86_64 2014-08-15
class_exists(" Imagick")= true

在这里,我尝试将配置文件分配给使用IM创建的图像,即使这不起作用.. 这有什么不对?

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();

编辑以下是我尝试使用Adobe RGB色彩空间的现有图像:

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();

1 个答案:

答案 0 :(得分:0)

我误读了你的要求。下面的代码将图像从Adobe风格的颜色配置文件更改为正常的'网络一。

$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");

现在使用识别图像检查:

# identify -verbose fullSize_MK3L7748.jpg | grep icc
    icc:name: Adobe RGB (1998)
    Profile-icc: 560 bytes

# identify -verbose test_blackScaled.jpg | grep icc
    icc:name: IEC 61966-2-1 Default RGB Colour Space - sRGB
    Profile-icc: 3048 bytes

图像应该看起来几乎相同 - 每个浏览器的确切结果可能会有所不同。

aRGB中的源图像 Source aRGB image

输出图像 Output image