【问题标题】:Imagick: unable to assign or convert color profileimagick:无法分配或转换颜色配置文件
【发布时间】:2015-04-24 12:23:48
【问题描述】:

我很难尝试将图像从 Adob​​e 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();

编辑这是我尝试使用 Adob​​e 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();

【问题讨论】:

    标签: imagick color-profile


    【解决方案1】:

    我误读了你的问题。下面的代码将图像从具有 Adob​​e 风格的颜色配置文件更改为“正常”的 Web 配置文件。

    $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 格式的源图像

    输出图像

    【讨论】:

    • 不,我已经用 Adob​​e RGB 颜色空间的现有图像尝试过这个,没有效果,它保持相同的配置文件。 $image = new Imagick(); $image->readImage("original-small.jpg"); $image->transformimagecolorspace(Imagick::COLORSPACE_SRGB);
    • 哎呀,我不相信!在前面添加斜杠就可以了! $image->transformImageColorspace(\Imagick::COLORSPACE_SRGB); 我差点放弃了.. 非常感谢!!知道为什么我需要斜线吗?
    • 不,等一下……不,我尝试使用 sRGB 的图像。使用 Adob​​e RGB 图像没有转换。我想我放弃了.. :-|我的主人也没有任何帮助。
    • 你能试试我贴的最上面的图片吗?它是一张 Adob​​e RGB 图片,显然结果应该和我得到的一样。
    • 您好 Danack,感谢您的帮助。我无法尝试使用您的图片,因为配置文件不再存在,可能是因为 StackOverflow?我在这里放了一个页面:goo.gl/zcjktQ 看来我对 color space vs profile vs color model i> 显然 Adob​​e RGB 配置图像仍然是 sRGB 色彩空间??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    相关资源
    最近更新 更多