(PHP 4, PHP 5, PHP 7, PHP 8)
imagefilledpolygon — 塗りつぶした多角形を描画する
PHP 8.0.0 以降のシグネチャ(名前付き引数をサポートしていません)
代替のシグネチャ (PHP 8.1.0 以降 は非推奨)
imagefilledpolygon() は画像 image
上に塗りつぶした多角形を生成します。
image
imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。
points
多角形の頂点の座標 x
および y
を含む配列。
num_points
頂点の総数。 3 以上である必要があります。
代替のシグネチャ(PHP 8.0.0 以降) でこの引数が省略された場合、points
は偶数でなければいけません。また、 num_points
は count($points)/2
であると仮定されます。 color
imagecolorallocate() で作成された色識別子。
バージョン | 説明 |
---|---|
8.1.0 | 引数 num_points は、推奨されなくなりました。 |
8.0.0 | image は、 GdImage クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な gd resource が期待されていました。 |
例1 imagefilledpolygon() の例
<?php
// 多角形の点の配列を準備します
$values = array(
40, 50, // Point 1 (x, y)
20, 240, // Point 2 (x, y)
60, 60, // Point 3 (x, y)
240, 20, // Point 4 (x, y)
50, 40, // Point 5 (x, y)
10, 10 // Point 6 (x, y)
);
// 画像を生成します
$image = imagecreatetruecolor(250, 250);
// 色を割り当てます
$bg = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 0, 0, 255);
// 背景を塗りつぶします
imagefilledrectangle($image, 0, 0, 249, 249, $bg);
// 多角形を描画します
imagefilledpolygon($image, $values, 6, $blue);
// 画像を出力します
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
上の例の出力は、 たとえば以下のようになります。