Forum und email

imagepolygon

(PHP 4, PHP 5)

imagepolygon — 多角形を描画する

説明

bool imagepolygon ( resource $image , array $points , int $num_points , int $color )

imagepolygon() は、指定した image に多角形を作成します。

パラメータ

image

imagecreatetruecolor() のような画像作成関数が返す画像リソース。

points

多角形の頂点からなる PHP の配列で、 points[0] = x0, points[1] = y0, points[2] = x1, points[3] = y1 というようになります。

num_points

頂点の総数。

color

imagecolorallocate() で作成した色 ID。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

Example#1 imagepolygon() の例

<?php
// 空の画像を生成します
$image imagecreatetruecolor(400300);

// 背景色を塗ります
$bg imagecolorallocate($image000);

// 多角形の色を選択します
$col_poly imagecolorallocate($image255255255);

// 多角形を描画します
imagepolygon($image, array (
        
0,   0,
        
100200,
        
300200
    
),
    
3,
    
$col_poly);

// 画像を出力します
header("Content-type: image/png");
imagepng($image);

?>

上の例の出力は、たとえば 以下のようになります。