imagefilledpolygon

(PHP 4, PHP 5, PHP 7, PHP 8)

imagefilledpolygon畫一多邊形并填充

說明

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

imagefilledpolygon()image 圖像中畫一個(gè)填充了的多邊形。

points 參數(shù)是一個(gè)按順序包含有多邊形各頂點(diǎn)的 xy 坐標(biāo)的數(shù)組。

num_points 參數(shù)是頂點(diǎn)的總數(shù),必須大于 3。

示例 #1 imagefilledpolygon() 例子

<?php
// 建立多邊形各頂點(diǎn)坐標(biāo)的數(shù)組
$values = array(
            
40,  50,  // Point 1 (x, y)
            
20,  240// Point 2 (x, y)
            
60,  60,  // Point 3 (x, y)
            
24020,  // Point 4 (x, y)
            
50,  40,  // Point 5 (x, y)
            
10,  10   // Point 6 (x, y)
            
);

// 創(chuàng)建圖像
$image imagecreatetruecolor(250250);

// 設(shè)定顏色
$bg   imagecolorallocate($image200200200);
$blue imagecolorallocate($image00255);

// 畫一個(gè)多邊形
imagefilledpolygon($image$values6$blue);

// 輸出圖像
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>