1

有背景图片。(对于这个例子mesh.png

图像需要添加一个圆圈,边框模糊。目前有这个:

use 5.014;
use warnings;
use Image::Magick;

my $bgimg = Image::Magick->new();
$bgimg->Read('png:mesh.png');

draw_my_circle($bgimg, 150, 150, 100);  #img, center_x, center_y, radius
$bgimg->Write("win:");  #display

sub draw_my_circle {
    my($img, $center_x, $center_y, $radius) = @_;
    $img->Draw(
        fill => 'black',
        points => "$center_x,$center_y @{[$center_x + $radius]},$center_y",
        primitive => 'circle',
    );
}

这将产生下一个图像:

网格上的黑色圆圈

但我需要一个带有“模糊边缘”的圆圈,就像下一个(手动创建)

网格上的模糊圆圈

任何人都可以帮助如何使用Image::Magick获得如此模糊的圆圈吗?

如果有人想要mesh.png,它是用下一个脚本创建的:

use 5.014;
use warnings;
use Image::Magick;

my $image=Image::Magick->new(size=>'300x300');
$image->Read('xc:white');

for( my $i=0; $i < 300; $i += 10 ) {
    $image->Draw(primitive=>'line',points=>"$i,0 $i,300",stroke=>"#ccf");
    $image->Draw(primitive=>'line',points=>"0,$i 300,$i",stroke=>"#ccf");
}
$image->Write('png:mesh.png');
4

1 回答 1

3

您可以使用高斯模糊,如下所示:

#!/usr/bin/perl
use 5.014;
use strict;
use warnings;
use Image::Magick;
my $x;
my $circle;
my $mesh;

$mesh=Image::Magick->new(size=>'300x300');
$mesh->Read('xc:white');

for( my $i=0; $i < 300; $i += 10 ) {
    $mesh->Draw(primitive=>'line',points=>"$i,0 $i,300",stroke=>"#ccf");
    $mesh->Draw(primitive=>'line',points=>"0,$i 300,$i",stroke=>"#ccf");
}
$mesh->Write(filename=>'mesh.png');

$circle=Image::Magick->new(size=>'300x300');
$circle->ReadImage('xc:transparent');
$circle->Draw(
        fill => 'black',
        points => "150,150 @{[250]},100",
        primitive => 'circle',
    );
$circle->GaussianBlur('10x50');
$circle->Write(filename=>'circle.png');

$mesh->Composite(image => $circle, qw(compose SrcAtop  gravity Center));
$mesh->Write(filename=>'out.png');
于 2014-07-01T16:49:47.300 回答