(PHP 4, PHP 5, PHP 7, PHP 8)
imagefilledpolygon — Dibujar un polígono con relleno
imagefilledpolygon() crea un polígono relleno
en image.
imageUn recurso image, es devuelto por una de las funciones de creación de imágenes, como imagecreatetruecolor().
points
Una matriz que contiene las coordenadas x e
y de los vértices del polígono consecutivamente.
num_pointsNúmero total de vértices, lo que debe ser al menos 3.
colorUn identificador de color creado con imagecolorallocate().
Ejemplo #1 Ejemplo de imagefilledpolygon()
<?php
// establecer una matriz de puntos para el polígono
$valores = 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)
);
// crear imagen
$imagen = imagecreatetruecolor(250, 250);
// asignar colores
$fondo = imagecolorallocate($imagen, 0, 0, 0);
$azul = imagecolorallocate($imagen, 0, 0, 255);
// rellenar el fondo
imagefilledrectangle($imagen, 0, 0, 249, 249, $fondo);
// dibujar un polígono
imagefilledpolygon($imagen, $valores, 6, $azul);
// volcar imagen
header('Content-type: image/png');
imagepng($imagen);
imagedestroy($imagen);
?>El resultado del ejemplo sería algo similar a: