用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - perl代码库

Image::Magick

2012-10-18 作者: 神马举报

[perl]代码库

QUOTE:
#!/usr/local/bin/perl
use Image::Magick;

my ( $image, $x );

$image = Image::Magick->new;
$x = $image->Read ( 'girl.png', 'logo.png', 'rose.png' );
warn "$x" if "$x";

$x = $image->Crop ( geometry=>'100x100"+100"+100' );
warn "$x" if "$x";

$x = $image->Write ( 'x.png' );
warn "$x" if "$x";


The script reads three images, crops them, and writes a single image as a GIF animation
sequence. In many cases you may want to access individual images of a sequence. The next
example illustrates how this is done:



QUOTE:
#!/usr/local/bin/perl
use Image::Magick;

my ( $image, $p, $q );

$image = new Image::Magick;
$image->Read ( 'x1.png' );
$image->Read ( 'j*.jpg' );
$image->Read ( 'k.miff[1, 5, 3]' );
$image->Contrast();
for ( $x = 0; $image->[x]; $x++ )
{
	$image->[x]->Frame ( '100x200' ) if $image->[x]->Get ( 'magick' ) eq 'GIF';
	undef $image->[x] if $image->[x]->Get ( 'columns' ) < 100;
}
$p = $image->[1];
$p->Draw ( stroke=>'red', primitive=>'rectangle', points=>20,20 100,100');
           $q = $p->Montage();
           undef $image;
           $q->Write('x.miff');


           Suppose you want to start out with a 100 by 100 pixel white canvas with a red pixel in the
           center. Try



           QUOTE:$image = Image::Magick->new;
           $image->Set(size=>'100x100');
           $image->ReadImage('xc:white');
           $image->Set('pixel[49,49]'=>'red');


           Or suppose you want to convert your color image to grayscale:



           QUOTE:$image->Quantize(colorspace=>'gray');

           Here we annotate an image with a Taipai TrueType font:

           $text = 'Works like magick!';
           $image->Annotate(font=>'kai.ttf', pointsize=>40, fill=>'green', text=>$text);


           Other clever things you can do with a PerlMagick objects include



           QUOTE:$i = $#$p"+1"; # return the number of images associated with object p
           push(@$q, @$p); # push the images from object p onto object q
           @$p = (); # delete the images but not the object p
           $p->Convolve([1, 2, 1, 2, 4, 2, 1, 2, 1]); # 3x3 Gaussian kernel



网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...