Ernests's code for Draw a Polygon (lines and square)
SLAVE CODE FOLLOWS
<?php
// create a blank image that is 400 by 300 pixels in size
$image = imagecreate(400, 300);
// set the background color to #EEEEEE
$na = imagecolorallocate($image, 238, 238, 238);
// BLUE color for triangle
$color = imagecolorallocate($image, 0, 0, 255);
// Triangle coordinates
$triangle = array(10, 20, 100, 200, 300, 200);
$pts = count($triangle) / 2;
// Outline + filled triangle
imagepolygon($image, $triangle, $pts, $color);
imagefilledpolygon($image, $triangle, $pts, $color);
// Frame coordinates
$frame = array(0,0, 399,0, 399,299, 0,299, 0,0);
$pts = count($frame) / 2;
// RED frame
$color = imagecolorallocate($image, 255, 0, 0);
imagepolygon($image, $frame, $pts, $color);
// Tell browser a PNG image is coming
header("Content-type: image/png");
// Output image
imagepng($image);
// Free memory
imagedestroy($image);
?>