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 |
by: 发表于:2017-09-11 11:51:45 顶(0) | 踩(0) 回复
??
回复评论