Draw a Triangle in PHP

Description

The following code shows how to draw a Triangle.

Example


<?php//from  w ww. ja  v  a  2 s .c  o  m
     header ("Content-type: image/png");
   
     $im = ImageCreate (175, 175);
   
     $grey = ImageColorAllocate ($im, 230, 230, 230);
     $black = ImageColorAllocate ($im, 0, 0, 0);
   
     $coordinates = array();
   
     $coordinates[0] = 0;            // Point 1 x
     $coordinates[1] = 150;          // Point 1 y
     $coordinates[2] = 150;          // Point 2 x
     $coordinates[3] = 150;          // Point 2 y
     $coordinates[4] = 75;           // Point 3 x
     $coordinates[5] = 75;           // Point 3 y
   
     ImageFilledPolygon($im, $coordinates, 3, $black);
   
     ImageString($im, 3, 5, 5, "Triangle", $black);
     ImagePng ($im);
     ImageDestroy ($im);
?>

The code above generates the following result.

Draw a Triangle in PHP




















Home »
  PHP Tutorial »
    Image »




Color
Create
Font
Operation
Shape
Text