★ wanayoo — archive 1999 http://php.net/manual/cs/function.imagepolygon.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Graphics
Quick Reference
English version of this pageGerman version of this pageJapanese version of this page
Italian version of this pageFrench version of this pageHungarian version of this page
Spanish version of this pageDutch version of this pageBrazilian Portuguese version of this page
Korean version of this pageCzech version of this page
Graphics
* GetImageSize
* ImageArc
* ImageChar
* ImageCharUp
* ImageColorAllocate
* ImageColorDeAllocate
* ImageColorAt
* ImageColorClosest
* ImageColorExact
* ImageColorResolve
* ImageGammaCorrect
* ImageColorSet
* ImageColorsForIndex
* ImageColorsTotal
* ImageColorTransparent
* ImageCopy
* ImageCopyResized
* ImageCreate
* ImageCreateFromGIF
* ImageCreateFromJPEG
* ImageCreateFromPNG
* ImageCreateFromWBMP
* ImageCreateFromString
* ImageDashedLine
* ImageDestroy
* ImageFill
* ImageFilledPolygon
* ImageFilledRectangle
* ImageFillToBorder
* ImageFontHeight
* ImageFontWidth
* ImageGIF
* ImagePNG
* ImageJPEG
* ImageWBMP
* ImageInterlace
* ImageLine
* ImageLoadFont
* ImagePolygon
* ImagePSBBox
* ImagePSEncodeFont
* ImagePSFreeFont
* ImagePSLoadFont
* ImagePsExtendFont
* ImagePsSlantFont
* ImagePSText
* ImageRectangle
* ImageSetPixel
* ImageString
* ImageStringUp
* ImageSX
* ImageSY
* ImageTTFBBox
* ImageTTFText
* ImageTypes
* read_exif_data

  Thanks to:
 Chek.com
 easyDNS
 VA Linux Systems

  Related sites:
Apache
MySQL
PostgreSQL
Zend Tech.

  Community:
LinuxFund.org
OSDN
Manual: ImagePolygon
View the source code for this pageSearch the site



Previous page
 ImageLoadFont
 Updated
Thu, 01 Mar 2001
ImagePSBBox 
Next page


ImagePolygon

(PHP 3, PHP 4 )

ImagePolygon -- Draw a polygon

Description

int imagepolygon (int im, array points, int num_points, int col)

ImagePolygon() creates a polygon in image id. Points is a PHP array containing the polygon's vertices, ie. points[0] = x0, points[1] = y0, points[2] = x1, points[3] = y1, etc. Num_points is the total number of vertices.

See also imagecreate().


User Contributed Notes: ImagePolygon


ecofarm@mullum.com.au
25-Jan-2001 09:37am
Create an array of points for the polygon... example script follows

(note you may have to change png to gif or whatever image format your version of php is configured with)


<pre>
&lt;?php

Header ("Content-type: image/png");

/////// set up array of points for polygon ///////

$a = array(
"0" => "40", // x1
"1" => "50", // y1
"2" => "20", // x2
"3" => "240", // y2
"4" => "60", // x3
"5" => "60", // y3
"6" => "240", // x4
"7" => "20", // y4
"8" => "50", // x5
"9" => "40", // y5
"10" => "10", // x6
"11" => "10", // y6
);

///// create canvas /////

$im = ImageCreate (250, 250);

//define colors.. first color declared is set as background

$white = ImageColorAllocate ($im, 255, 255, 255);
$blue = ImageColorAllocate ($im, 0, 0, 255);


// draw a polygon

ImageFilledPolygon ($im, $a, 6, $blue );

// create the image

ImagePng ($im);

// destroy the image to free memory

ImageDestroy ($im);
?>
</pre>



jsnell@networkninja.com
17-Feb-2001 07:07pm
Here are some handy routines for rotation and translation of polygons. Scaling could be added easily as well.

function translate_point(&$x,&$y,$angle,$about_x,$about_y,$shift_x,$shift_y)
{
$x -= $about_x;
$y -= $about_y;
$angle = ($angle / 180) * M_PI;
/* math:
[x2,y2] = [x, * [[cos(a),-sin(a)],
y] [sin(a),cos(a)]]
==>
x = x * cos(a) + y*sin(a)
y = x*-sin(a) + y*cos(a)
*/

$new_x = $x * cos($angle) - $y * sin($angle);
$new_y = $x * sin($angle) + $y * cos($angle);
$x = $new_x+ $about_x + $shift_x ;
$y = $new_y + $about_y + $shift_y;
}

function translate_poly($point_array, $angle, $about_x, $about_y,$shift_x,$shift_y)
{
$translated_poly = Array();
while(count($point_array) > 1)
{
$temp_x = array_shift($point_array);
$temp_y = array_shift($point_array);
translate_point($temp_x, $temp_y, $angle, $about_x, $about_y,$shift_x, $shift_y);
array_push($translated_poly, $temp_x);
array_push($translated_poly, $temp_y);
}
return $translated_poly;
}



 About Notes


Previous page
 ImageLoadFont
 Updated
Thu, 01 Mar 2001
ImagePSBBox 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.