ポリゴンを描画した画像をPerlモジュールのImage::Magickで生成
PerlモジュールのImage::Magickを使用して、多角形を描画した画像を出力しました。Drawメソッドのprimitiveパラメータをpolygonに指定して処理を実行しています。)
#!/opt/local/bin/perl use strict; use warnings; use Image::Magick; my $image = Image::Magick->new(magick => "png"); $image->Set("600x400"); $image->ReadImage("xc:none"); $image->Draw( antialias => "true", fill => "none", points => "100,100 500,100 300,300", primitive => "polygon", stroke => "black", strokewidth => 100, x => 0, y => 0 ); print "Content-type: image/png\n\n"; $image->Write("png:-"); undef $image; exit;
サンプルコードと出力結果です。ポリゴンを描画した画像を出力しました。pointsで始点から終点までの各X座標とY座標を指定します。描画する形状はprimitiveで、ポリゴンを描く場合はpolygonに、fillで塗り潰す色を指定します。strokeで描画する図形の枠線の色、strokewidthで描画する図形の枠線の太さを指定できます。