如何使用ImageMagick模糊/像素化图像的一部分? [英] How to blur/pixelate part of an image using ImageMagick?

查看:380
本文介绍了如何使用ImageMagick模糊/像素化图像的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Perl和ImageMagick(Perl-API)。
在第一步中,我想拍摄图像的矩形并模糊图像的这一部分。期望的结果是具有矩形模糊的原始图像。

I am using Perl and ImageMagick (Perl-API). In a first step i would like to take a rectangle of an image and blur this part of the image. Desired result is the original image with the rectangle blured.

在第二步中,我需要模糊具有转动矩形的图像的一部分(即转动35%) 。

In a second step i need to blur a part of an image with a turned rectangle (i.e. turned by 35%).

我如何实现这一目标?

推荐答案

当你要求PerlMagick时,我把剩下的最后几张头发拉出去尝试在Perl中执行...文件 1.png 2.png 3.png 纯粹是为了调试,所以你可以看到我在做什么。

As you asked for PerlMagick, I pulled my last few remaining hairs out to try and do this in Perl... the files 1.png, 2.png and 3.png are purely for debug so you can see what I am doing.

#!/usr/bin/perl
use strict;
use warnings;
use Image::Magick;
my $x;
my $image;
my $blurred;
my $mask;

# Create original fishscale image
$image=Image::Magick->new(size=>'600x300');
$image->Read('pattern:fishscales');
$image->Write(filename=>"1.png");

# Copy original image and blur
$blurred = $image->Clone();
$blurred->GaussianBlur('x2');
$blurred->Write(filename=>"2.png");

# Make mask and rotate
$mask=Image::Magick->new(size=>'600x300');
$mask->Read('xc:white');
$mask->Draw(fill=>'black',primitive=>'rectangle',points=>'100,100,200,200');
$mask->Set('virtual-pixel'=>'white');
$mask->Rotate(20);
$mask->Transparent('white');
$mask->Write(filename=>"3.png");

# Copy mask as alpha channel into blurred image
$blurred->Composite(image=>$mask,qw(compose CopyOpacity gravity center));

# Composite blurred image onto original
$image->Composite(image=>$blurred);
$image->Write(filename=>'result.png');

以下是调试图片......

Here are the debug images...

1.png

2.png

3.png

result.png

在这里输入的图像描述

可能会更快,更简单,更多这样做的有效方法,但我不知道,并且那里有很少的PerlMagick例子,所以我会把我的标记放在沙子中,看看是否有人可以更好: - )

There may be a much faster, simpler, more efficient way of doing this, but I don't know it, and there are precious few examples of PerlMagick out there, so I'll stick my marker in the sand and see if anyone can better it:-)

PS不要为我的头发感觉不好 - 无论如何只剩下三个: - )

P.S. Don't feel bad about my hair - there were only three left anyway :-)

这篇关于如何使用ImageMagick模糊/像素化图像的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆