繁体   English   中英

为什么Perl的Image :: Magick在半透明图像周围创建轮廓但复合图像不是?

[英]Why does Perl's Image::Magick create an outline around a semi-transparent image but composite doesn't?

我正在开发一个程序,用Image :: Magick动态地为产品图像添加水印。 我正在使用compositedissolve方法。 水印图像是具有透明度的PNG。 它使用ImageMagick 6.7.6-9 2012-05-16 Q16在Linux上运行。

考虑以下任意示例图像:

背景( test.jpg ):

背景(产品图片)

水印/叠加( example.png ):

示例水印

如果我将这些与命令行工具composite一起放在一起,一切都很棒。

composite -dissolve 60% -gravity center example.png test.jpg out.jpg

正确输出CLI

文本(这需要是一个图像,其中也会有图形)叠加在背景上。 边缘就像它们在原始水印图像中的方式。

#!/usr/bin/perl
use strict; use warnings;
use Image::Magick;

# this objects represents the background
my $background = Image::Magick->new;
$background ->ReadImage( 'test.jpg' );

# this objects represents the watermark
my $watermark = Image::Magick->new;
$watermark->ReadImage( 'example.png');

# there is some scaling going on here...
# both images are scaled down to have the same width
# but the problem occurs even if I turn the scaling off

# superimpose the watermark
$background->Composite(
  image    => $watermark,
  compose  => 'Dissolve',
  opacity  => '60%',
  gravity  => 'Center',
);

$background->Write( filename => 'out.jpg' );

这是Perl程序的输出:

Perl程序的奇怪输出

如您所见,新图像有一些奇怪的边缘,几乎像一个轮廓。 此图像越大(原始源图像均> 1000px),此轮廓变得越明显。

这是一个特写:

Closup正确的图像

不正确的图象特写镜头

我相信它可能与JPEG压缩的强度有关,因为错误的图像有更多的人工制品。 但这意味着Perl的Image :: Magick和CLI的默认值不同。 我还没弄清楚如何设置压缩。

无论如何,对于为什么会发生这种情况,或者如何摆脱它的想法和建议,我会很高兴。

我快速浏览了一下PerlMagick源代码,当溶解的图像有alpha通道时,似乎Composite with Dissolve是错误的。 以下适用于我:

$watermark->Evaluate(
  operator => 'Multiply',
  value    => 0.6,
  channel  => 'Alpha',
);

$background->Composite(
  image    => $watermark,
  gravity  => 'Center',
);

暂无
暂无

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

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