代碼以下: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;