Draw Polygons Using imagepolygon() in PHP

Description

The following code shows how to draw Polygons Using imagepolygon().

Example


<?php//from   ww  w  .j  a v a  2  s .c  o m

    define("WIDTH", 100);
    define("HEIGHT", 100);

    $img = imagecreate(WIDTH, HEIGHT);
    $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
    $black = Imagecolorallocate($img, 0, 0, 0);

    $points = array(0, 0,                // Vertex (0,0)
                    0, HEIGHT,           // Vertex (0, HEIGHT)
                    (int)WIDTH/2, 0,     // Vertex (WIDTH/2, 0)
                    WIDTH-1, HEIGHT-1,   // Vertex (WIDTH, HEIGHT)
                    WIDTH-1, 0);         // Vertex (WIDTH, 0)

    imagepolygon($img, $points, 5, $black);

    header("Content-type: image/png");
    imagepng($img);

?>

The code above generates the following result.

Draw Polygons Using imagepolygon() in PHP




















Home »
  PHP Tutorial »
    Image »




Color
Create
Font
Operation
Shape
Text