PerlMagick经验

画个图片

fig4.5

代码以下:code

#!/usr/bin/perl

use strict;
use warnings;
use Image::Magick;

my $png = 'IM_example.png';

my $im = Image::Magick->new(size => '400x300');

# add a white image, and set the default color
my $rc = $im->Read('xc:white');
warn $rc if $rc;
$im->Set(stroke => 'red');

# draw a rectangle
# primitive => 图元,基元特征
$im->Draw(
    primitive => 'rectangle',
    points => '0,129 199,169',
    fill => 'blue',
    stroke => 'blue'
);

# draw a polygon
$im->Draw(
    primitive => 'polygon',
    points => '199,149 399,74 324,149 399,224',
    fill => 'yellow',
    stroke => 'black'
);

# Tweak some parameters. tweak: 对…稍做调整,对程序微调
$im->Set(antialias => 0, fuzz => 15); # 1. 抗锯齿,平滑 2. 模糊;绒毛

# draw a circle and cut out an ellipse
$im->Draw(
    primitive => 'circle',
    strokewidth => 3,
    points => '199,149 74,149',
    fill => 'none' # added by lhtk
);
$im->Draw(
    primitive => 'ellipse', # 椭圆
    strokewidth => 3,
    points => '199,149 50,100 0,360',
    fill => 'none' # added by lhtk
);

# flood-fill the gap
$im->Draw(
    primitive => 'color',
    method => 'filltoborder',
    points => '99,149',
    bordercolor => 'red',
    fill => 'green1'
);

# frame with a red border and cross
$im->Draw(
    primitive => 'rectangle',
    points => '0,0 399,299',
    fill => 'none'
);
$im->Draw(
    primitive => 'line',
    points => '199,0 199,299'
);
$im->Draw(
    primitive => 'line',
    points => '0,149 399,149'
);
$rc = $im->Write($png);
warn $rc if $rc;
相关文章
相关标签/搜索