Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imagepolygon

Description

The imagepolygon of Image for PHP draws a polygon.

Syntax

imagepolygon(
    GdImage $image,
    array $points,
    int $color
): bool

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().

points

An array containing the x and y coordinates of the polygons vertices consecutively.

color

A color identifier created with imagecolorallocate().

Return

Returns true on success or false on failure.

Examples

1 · return

<?

$width = 100;
$height = 100;
$image = imagecreate($width, $height);

$red = 255;
$green = 255;
$blue = 255;
$color = imagecolorallocate($image, $red, $green, $blue);

$points = array(
    0, 50,
    50, 0,
    100, 50,
    50, 100
);

$return = imagepolygon($image, $points, $color);
    
var_export($return);

?>
true

2 · base64

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$red = 255;
$green = 255;
$blue = 255;
$color = imagecolorallocate($image, $red, $green, $blue);

$points = array(
    0, 50,
    50, 0,
    100, 50,
    50, 100
);
imagepolygon($image, $points, $color);

ob_start();

    imagepng($image);

$output = ob_get_clean();

echo '<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';

?>
<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB7klEQVR4nO2cWY6DQBQDuf+lmQ9rREJY3NCL+z3XCcolJQrQYVkkWdd1tMIkoJR73fPZyL2u+K3jXsecdXGvPddF3GuDaeFey1JSIXuv0v15ez1bnrHXm825er1fm6VXrZ3xe9VdGLlXi20xe7VbFa1X6z1xevVZEqFXzw1z9+pvP2uvUd7z9RprPFMvBVcFh3t0LHVMjlHzU/PZ0DRTtFJ0+kfLTcvmCBVDFY87xnuONyhhpO1cpcAY5xlLgd7m85YC/fxnLwV6rIhRCrTdEqkUaLUoXilQf1fUUqDmutilQJ2NGUqBt0vzlALP92YrBZ6szlkKlG3PXAqwBVwK3HdwqU+uarjUL8dNXOqMfRmXumbr41IM67q6VCHuxeBPIou/41n864HFv0tZfMXD4mtpFt+lYfH9PxbfWWbxMwsWPw1j8XNWFj/BZ/HZEBafOmLxeTYWn5Rk8RlcFp/uZvH/BljG24434FDxVPE4R8tQy+YbRTdFJ1WrZdEzU/PZo+OnY3KFgqWCA4vfGFKG30VTht9yVIbfn1VGnw0RSoHWS+KUAu32RCsFWqyKWQrU3Ra5FKi1MH4p8H5nllLgzdpcpcCzzRlLgdLleUsBfn/2UoCp4FIb1y1cas9ZEZc65reLS13xWcel7kEjwVJ/y9ZPzSdNjH0AAAAASUVORK5CYII=">
</body>
</html>
HomeMenu