1--TEST--
2imagefilledpolygon()
3--SKIPIF--
4<?php
5	if (!function_exists('imagefilledpolygon')) die('skip imagefilledpolygon() not available');
6	if (!(imagetype() & IMG_PNG)) die('skip PNG Support is not enabled');
7?>
8--FILE--
9<?php
10
11/* Prototype  : bool imagefilledpolygon  ( resource $image  , array $points  , int $num_points  , int $color  )
12 * Description: Draws a filled polygon.
13 * Source code: ext/standard/image.c
14 * Alias to functions:
15 */
16
17echo "Simple test of imagefilledpolygon() function\n";
18
19$dest = dirname(realpath(__FILE__)) . '/imagefilledpolygon.png';
20
21$points = array(
22            40,  50,
23            20,  240,
24            60,  60,
25            240, 20,
26            50,  40,
27            10,  10
28            );
29
30// create a blank image
31$image = imagecreatetruecolor(250, 250);
32
33// set the background color to black
34$bg = imagecolorallocate($image, 0, 0, 0);
35
36// fill polygon with green
37$col_poly = imagecolorallocate($image, 0, 255, 0);
38
39// draw the polygon
40imagefilledpolygon($image, $points, count($points)/2, $col_poly);
41
42// output the picture to a file
43imagepng($image, $dest);
44
45// get it back
46$image_in = imagecreatefrompng($dest);
47
48//check color of a point on edge..
49$col1 = imagecolorat($image_in, 40, 50);
50//.. a point in filled body
51$col2 = imagecolorat($image_in, 15, 15);
52// ..and a point on background
53$col3 = imagecolorat($image_in, 5, 5);
54
55$color1 = imagecolorsforindex($image_in, $col1);
56$color2 = imagecolorsforindex($image_in, $col2);
57$color3 = imagecolorsforindex($image_in, $col3);
58var_dump($color1, $color2, $color3);
59
60imagedestroy($image);
61imagedestroy($image_in);
62
63echo "Done\n";
64?>
65--CLEAN--
66<?php
67	$dest = dirname(realpath(__FILE__)) . '/imagefilledpolygon.png';
68	@unlink($dest);
69?>
70--EXPECT--
71Simple test of imagefilledpolygon() function
72array(4) {
73  ["red"]=>
74  int(0)
75  ["green"]=>
76  int(255)
77  ["blue"]=>
78  int(0)
79  ["alpha"]=>
80  int(0)
81}
82array(4) {
83  ["red"]=>
84  int(0)
85  ["green"]=>
86  int(255)
87  ["blue"]=>
88  int(0)
89  ["alpha"]=>
90  int(0)
91}
92array(4) {
93  ["red"]=>
94  int(0)
95  ["green"]=>
96  int(0)
97  ["blue"]=>
98  int(0)
99  ["alpha"]=>
100  int(0)
101}
102Done
103