David wrote:
Is it possible to create more than one polygon (using the imagepolygon
function) and then paste them on to one image? i have no idea how to do
this. I did post this a few days ago but my computer seems to have lost the
reply,
thanks Dave
The original response you got (from Pedro Graca) was:
What have you tried?
What happenned? What did you want to happen?
After taking a look at the sample code from PHP.net I can see how
somebody new-ish to PHP might be a bit confused. (An array is defined
within a function call, etc... not the world's clearest example, IMHO.)
Here's a hopefully clear(er) version. Also, note that I intentionally
chose long, descriptive variable names to hopefully help clarify what's
going on in the script. You probably won't want to use
reallySuperStinkingLongVariableNames in your scripts. ;)
- Dan
http://blog.dantripp.com/
================================================== =========
Modified version of the sample at:
http://www.php.net/manual/en/function.imagepolygon.php
================================================== =========
<?php
// create a blank image
$image = imagecreate(400, 300);
// fill the background color
$bg = imagecolorallocate($image, 0, 0, 0);
// choose a color for the polygon
$polygonOneColor = imagecolorallocate($image, 255, 255, 255);
$polygonTwoColor = imagecolorallocate($image, 160, 160, 160);
// Put the points for each polygon into an array, for the sake of
// showing simpler code than declaring an array within a
// function. (like the sample above)
// Also, I padded the values below with spaces, just to make these
// easier for human eyes to read. (aka - it's not necessary)
$polygonOnePoints = array( 0, 0, 200,200, 200,300);
$polygonTwoPoints = array(300,270, 250,225, 375,275);
// A smarter way to determine the number of points would be to count the
// # of items in the polygon's Points array and divide by 2 (left as an
// exercise for the reader).
$polygonOneNumberOfPoints = 3;
$polygonTwoNumberOfPoints = 3;
// draw the first polygon
imagepolygon($image,$polygonOnePoints,$polygonOneN umberOfPoints,$polygonOneColor);
// draw the second polygon
imagepolygon($image,$polygonTwoPoints,$polygonTwoN umberOfPoints,$polygonTwoColor);
// output the picture
header("Content-type: image/png");
imagepng($image);
?>