php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #64641
Patch git-am revision 2015-07-20 22:06 UTC by cmb@php.net

Patch git-am for GD related Bug #64641

Patch version 2015-07-20 22:06 UTC

Return to Bug #64641 | Download this patch
Patch Revisions:

Developer: cmb@php.net

From 3c47748485edb6f5d02ff24d557caa8f2a3a8a2f Mon Sep 17 00:00:00 2001
From: "Christoph M. Becker" <cmb@php.net>
Date: Mon, 20 Jul 2015 21:44:11 +0200
Subject: [PATCH] Fix #64641: imagefilledpolygon doesn't draw horizontal line

Filled polygons are drawn by repeatedly drawing respective horizontal lines.
This doesn't work, however, for 1d polygons (i.e. all y coordinates are
identical). This patch adds handling for this special case by simply delegating
to gdImagePolygon().
---
 ext/gd/libgd/gd.c          |  5 +++++
 ext/gd/tests/bug64641.phpt | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 ext/gd/tests/bug64641.phpt

diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
index 3460292..c0248d5 100644
--- a/ext/gd/libgd/gd.c
+++ b/ext/gd/libgd/gd.c
@@ -2662,6 +2662,11 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
 		maxy = gdImageSY(im) - 1;
 	}
 
+	if (miny == maxy) {
+		gdImagePolygon(im, p, n, c);
+		return;
+	}
+
 	/* Fix in 1.3: count a vertex only once */
 	for (y = miny; y <= maxy; y++) {
 		/*1.4           int interLast = 0; */
diff --git a/ext/gd/tests/bug64641.phpt b/ext/gd/tests/bug64641.phpt
new file mode 100644
index 0000000..74deb02
--- /dev/null
+++ b/ext/gd/tests/bug64641.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Bug #64641 (imagefilledpolygon doesn't draw horizontal line)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$im = imagecreatetruecolor(400, 200);
+$white = imagecolorallocate($im, 255, 255, 255);
+$black = imagecolorallocate($im, 0, 0, 0);
+imagefill($im, 0, 0, $white);
+$points = array(100, 100, 200, 100, 300, 100);
+imagefilledpolygon($im, $points, 3, $black);
+var_dump(imagecolorat($im, 200, 100) === $black);
+?>
+--EXPECT--
+bool(true)
-- 
1.9.5.msysgit.0

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 11 17:01:27 2024 UTC