简体   繁体   English

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

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

I have one image (JPEG) that I want to seamlessly superimpose on another.我有一个图像 (JPEG),我想无缝地叠加在另一个图像上。 If I was trying to do this in Photoshop I would feather the edges.如果我在 Photoshop 中尝试这样做,我会羽化边缘。 But I cannot work out how to achieve this with the PerlMagick api.但是我不知道如何使用 PerlMagick api 来实现这一点。 I have tried using Vignette to create a fuzzy border, but that does not work as I would hope.我曾尝试使用 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:-');

The hard edge is caused by the x=>5, y=>5, parameters.硬边是由 x=>5, y=>5, 参数引起的。 Remove these and the radius value, and the images will merge as required.删除这些和半径值,图像将根据需要合并。 The hardlight in combination with the vignette process creates and area where both images are mixed.强光与小插图过程相结合,创建了两个图像混合的区域。 So the code should be:所以代码应该是:

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