com php-src: Fix #53154: Zero-height rectangle has whiskers: ext/gd/libgd/gd.c ext/gd/tests/bug53154.phpt

From: Date: Sun, 12 Jul 2015 23:29:01 +0000
Subject: com php-src: Fix #53154: Zero-height rectangle has whiskers: ext/gd/libgd/gd.c ext/gd/tests/bug53154.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-87983@lists.php.net to get a copy of this message
Commit: d87a3312e30931d0f6c2ea6a6ced13fc7b217e65 Author: Christoph M. Becker <cmb@php.net> Mon, 13 Jul 2015 01:29:01 +0200 Parents: ecd32e437e81270221092726eb1bdac6917994e0 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d87a3312e30931d0f6c2ea6a6ced13fc7b217e65 Log: Fix #53154: Zero-height rectangle has whiskers To avoid drawing the corner pixels twice, gdImageRectangle() draws the vertical lines 2 points shorter than the actual side of the rectangle. However, this causes "whiskers" for rectangles with height 0. This patch fixes this issue and at the same time optimizes the algorithm by drawing only a single line for zero height and zero width rectangles. Bugs: https://bugs.php.net/53154 Changed paths: M ext/gd/libgd/gd.c A ext/gd/tests/bug53154.phpt Diff: diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index 3164a2c..3460292 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -2093,12 +2093,16 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color) return; } else { - y1v = y1h + 1; - y2v = y2h - 1; - gdImageLine(im, x1h, y1h, x2h, y1h, color); - gdImageLine(im, x1h, y2h, x2h, y2h, color); - gdImageLine(im, x1v, y1v, x1v, y2v, color); - gdImageLine(im, x2v, y1v, x2v, y2v, color); + if (x1 == x2 || y1 == y2) { + gdImageLine(im, x1, y1, x2, y2, color); + } else { + y1v = y1h + 1; + y2v = y2h - 1; + gdImageLine(im, x1h, y1h, x2h, y1h, color); + gdImageLine(im, x1h, y2h, x2h, y2h, color); + gdImageLine(im, x1v, y1v, x1v, y2v, color); + gdImageLine(im, x2v, y1v, x2v, y2v, color); + } } } diff --git a/ext/gd/tests/bug53154.phpt b/ext/gd/tests/bug53154.phpt new file mode 100644 index 0000000..6cbae20 --- /dev/null +++ b/ext/gd/tests/bug53154.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #53154 (Zero-height rectangle has whiskers) +--SKIPIF-- +<?php +if (!extension_loaded('gd')) die('skip gd extension not available'); +?> +--FILE-- +<?php +$im = imagecreatetruecolor(100, 10); +$red = imagecolorallocate($im, 255, 0, 0); +imagerectangle($im, 5, 5, 95, 5, $red); +var_dump(imagecolorat($im, 5, 4) !== $red); +var_dump(imagecolorat($im, 5, 6) !== $red); +var_dump(imagecolorat($im, 95, 4) !== $red); +var_dump(imagecolorat($im, 95, 6) !== $red); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true)

« previous php.cvs (#87983) next »