繁体   English   中英

如何使用 PerlMagick “羽化”图像边缘

[英]How to “feather” the edges on image with PerlMagick

我有一个图像 (JPEG),我想无缝地叠加在另一个图像上。 如果我在 Photoshop 中尝试这样做,我会羽化边缘。 但是我不知道如何使用 PerlMagick api 来实现这一点。 我曾尝试使用 Vignette 创建一个模糊的边框,但这并不像我希望的那样工作。

use Image::Magick;

$file = 'background.jpg';
$image = Image::Magick->new;
open(IMAGE, $file ) or die "Error cannot open file: $file"; 
$image->Read(file=>\*IMAGE);
close(IMAGE);

$file = 'face.jpg';
$face = Image::Magick->new;
open(IMAGE, $file ) or die "Error cannot open file: $file"; 
$face->Read(file=>\*IMAGE);
close(IMAGE);

$face->Vignette (geometry=>'5x5', radius=>50, x=>5, y=>5, background=>none);

$image->Composite(image=>$face,compose=>'hardlight',geometry=>'+480+800');

print "Content-type: image/jpeg\n\n";
binmode STDOUT;
$image->Write('jpg:-');

硬边是由 x=>5, y=>5, 参数引起的。 删除这些和半径值,图像将根据需要合并。 强光与小插图过程相结合,创建了两个图像混合的区域。 所以代码应该是:

use Image::Magick;

$file = 'background.jpg';
$image = Image::Magick->new;
open(IMAGE, $file ) or die "Error cannot open file: $file"; 
$image->Read(file=>\*IMAGE);
close(IMAGE);

$file = 'face.jpg';
$face = Image::Magick->new;
open(IMAGE, $file ) or die "Error cannot open file: $file"; 
$face->Read(file=>\*IMAGE);
close(IMAGE);

$face->Vignette (geometry=>'5x5', background=>none);

$image->Composite(image=>$face,compose=>'hardlight',geometry=>'+480+800');

print "Content-type: image/jpeg\n\n";
binmode STDOUT;
$image->Write('jpg:-');

暂无
暂无

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

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