简体   繁体   English

当用Perl的Image :: Magick处理时,为什么我的PNG图像的颜色配置文件/空间会改变?

[英]Why do the color profile/spaces of my PNG images change when processed with Perl's Image::Magick?

I have encountered some quite puzzling behaviour with ImageMagick (using PerlMagick : I open a PNG picture, resize it, and saves it. 我在使用ImageMagick时遇到了一些令人费解的行为(使用PerlMagick :打开PNG图片,调整其大小并保存它。

All good, except that the resulting image colors' are slightly different. 一切都很好,除了所得的图像颜色略有不同。

# Create the ImageMagick object.
my $magick = Image::Magick->new;

eval {
    $magick->BlobToImage( $image );
};

$magick->Scale( ... );

# ...and then save it.

However, if I manually set the image's color space to "RGB" right before I save it, the images are similar color-wise; 但是,如果我在保存之前手动将图像的色彩空间设置为“ RGB”,则图像在颜色上是相似的。

$magick->Colorspace( colorspace => 'RGB' );

Why is this? 为什么是这样?

EDIT: If I do exactly the same, except setting the color space manually, but convert to JPEG before saving, the colors becomes correct. 编辑:如果我做完全一样,除了手动设置颜色空间, 在保存之前转换为JPEG,颜色将变为正确。 Even more puzzling. 更令人费解。 :-/ :-/

When the image is saved in PNG format using Image::Magick , a gAMA chunk is added as can be seen by comparing the output of gm identify -verbose modified.png with the output of gm identify -verbose original.png shows: 当使用Image::Magick将图像保存为PNG格式时,通过将gmidentification gm identify -verbose modified.png的输出与gm identify -verbose original.png的输出进行比较可以看到,添加了一个gAMA块,它显示:

$ fc original.info modified.info
***** original.info
      Standard Deviation:      18869.16 (0.2879)
  Filesize: 613.0Ki
  Interlace: No
***** MODIFIED.INFO
      Standard Deviation:      18869.16 (0.2879)
  Gamma: 0.45455
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Filesize: 614.2Ki
  Interlace: No
*****

The RGB color values in the files are the same, but the saved gamma correction information in the second file causes it to be displayed slightly differently than the original. 文件中的RGB颜色相同,但是在第二个文件中保存的伽玛校正信息使它的显示与原始显示略有不同。 That is why converting the image to JPG "fixes" the problem: It removes the gamma correction information. 这就是为什么将图像转换为JPG可以“解决”问题的原因:它删除了伽玛校正信息。

Looking at the ImageMagick source code , the stripping is achieved using: 查看ImageMagick源代码 ,使用以下方法实现剥离:

 SetImageArtifact(image,"png:exclude-chunk", "bKGD,cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date"); 

Therefore, I recommended the OP try: 因此,我建议OP尝试:

 $magick->Set(option => "png:exclude-chunk=gAMA");

in his Perl program, and the OP reported it solved the problem. 在他的Perl程序中,OP报告说它解决了问题。

Related information: 相关信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM