Skip to content

Commit

Permalink
Merge branch 'pull-request/2151'
Browse files Browse the repository at this point in the history
  • Loading branch information
cmb69 committed Oct 17, 2016
2 parents abd2c04 + 2a305b3 commit 0f49aa3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ PHP 7.2 UPGRADE NOTES

- GD:
. Added imagesetclip() and imagegetclip().
. Added imageopenpolygon().

- Mbstring:
. Added mb_chr() and mb_ord().
Expand Down
31 changes: 27 additions & 4 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagepolygon, 0)
ZEND_ARG_INFO(0, col)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_imageopenpolygon, 0)
ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
ZEND_ARG_INFO(0, num_pos)
ZEND_ARG_INFO(0, col)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_imagefilledpolygon, 0)
ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
Expand Down Expand Up @@ -936,6 +943,7 @@ const zend_function_entry gd_functions[] = {
PHP_FE(imageline, arginfo_imageline)
PHP_FE(imageloadfont, arginfo_imageloadfont)
PHP_FE(imagepolygon, arginfo_imagepolygon)
PHP_FE(imageopenpolygon, arginfo_imageopenpolygon)
PHP_FE(imagerectangle, arginfo_imagerectangle)
PHP_FE(imagesetpixel, arginfo_imagesetpixel)
PHP_FE(imagestring, arginfo_imagestring)
Expand Down Expand Up @@ -3346,6 +3354,7 @@ PHP_FUNCTION(imageinterlace)
/* }}} */

/* {{{ php_imagepolygon
arg = -1 open polygon
arg = 0 normal polygon
arg = 1 filled polygon */
/* im, points, num_points, col */
Expand Down Expand Up @@ -3398,10 +3407,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
gdImageSetAntiAliased(im, col);
col = gdAntiAliased;
}
if (filled) {
gdImageFilledPolygon(im, points, npoints, col);
} else {
gdImagePolygon(im, points, npoints, col);
switch (filled) {
case -1:
gdImageOpenPolygon(im, points, npoints, col);
break;
case 0:
gdImagePolygon(im, points, npoints, col);
break;
case 1:
gdImageFilledPolygon(im, points, npoints, col);
break;
}

efree(points);
Expand All @@ -3417,6 +3432,14 @@ PHP_FUNCTION(imagepolygon)
}
/* }}} */

/* {{{ proto bool imageopenpolygon(resource im, array point, int num_points, int col)
Draw a polygon */
PHP_FUNCTION(imageopenpolygon)
{
php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, -1);
}
/* }}} */

/* {{{ proto bool imagefilledpolygon(resource im, array point, int num_points, int col)
Draw a filled polygon */
PHP_FUNCTION(imagefilledpolygon)
Expand Down
12 changes: 11 additions & 1 deletion ext/gd/libgd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,17 @@ void gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, i
}

void gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)
{
if (n <= 0) {
return;
}


gdImageLine (im, p->x, p->y, p[n - 1].x, p[n - 1].y, c);
gdImageOpenPolygon (im, p, n, c);
}

void gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
{
int i;
int lx, ly;
Expand All @@ -2667,7 +2678,6 @@ void gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)

lx = p->x;
ly = p->y;
gdImageLine(im, lx, ly, p[n - 1].x, p[n - 1].y, c);
for (i = 1; i < n; i++) {
p++;
gdImageLine(im, lx, ly, p->x, p->y, c);
Expand Down
1 change: 1 addition & 0 deletions ext/gd/libgd/gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ typedef struct {
} gdPoint, *gdPointPtr;

void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c);
void gdImageOpenPolygon(gdImagePtr im, gdPointPtr p, int n, int c);
void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c);

/* These functions still work with truecolor images,
Expand Down
1 change: 1 addition & 0 deletions ext/gd/php_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ PHP_FUNCTION(imageinterlace);
PHP_FUNCTION(imageline);
PHP_FUNCTION(imageloadfont);
PHP_FUNCTION(imagepolygon);
PHP_FUNCTION(imageopenpolygon);
PHP_FUNCTION(imagerectangle);
PHP_FUNCTION(imagesetpixel);
PHP_FUNCTION(imagestring);
Expand Down
Binary file added ext/gd/tests/imageopenpolygon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions ext/gd/tests/imageopenpolygon_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
imageopenpolygon(): basic test
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
?>
--FILE--
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';

$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 0, 128, 0);
$blue = imagecolorallocate($im, 0, 0, 255);
imagefilledrectangle($im, 0,0, 99,99, $white);

imageopenpolygon($im, [10,10, 49,89, 89,10], 3, $black);
imageopenpolygon($im, [10,89, 35,10, 60,89, 85,10], 4, $red);
imageopenpolygon($im, [10,49, 30,89, 50,10, 70,89, 90,10], 5, $green);
imageopenpolygon($im, [10,50, 25,10, 40,89, 55,10, 80,89, 90,50], 6, $blue);

test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'imageopenpolygon.png', $im);
?>
===DONE===
--EXPECT--
The images are equal.
===DONE===

0 comments on commit 0f49aa3

Please sign in to comment.