Re: [GD-DEVEL] Polygon with holes

From: Date: Thu, 13 Sep 2007 03:46:42 +0000
Subject: Re: [GD-DEVEL] Polygon with holes
References: 1  Groups: php.gd.devel 
Request: Send a blank email to php-gd-devel+get-261@lists.php.net to get a copy of this message
On Sep 12, 2007, at 8:34 PM, Mateusz Loskot wrote:
Hi, Could anyone provide me with some tricks about what's the best and efficiently way to render filled polygon with one or more holes? IOW, how to render a donut-like polygon that's filled with red colour but internal ring is not filled (is displayed as transparent).
What I ended up doing in a recent project is creating a new paletted image buffer of image size and allocate two colors, black and white. The black is allocated first and fills the background. Then I drew the non-hole parts of the polygon in white, without anti-aliasing. (GD's antialiasing isn't great for polygons with dense vertices anyway.) Then I drew the holes back in black. Once that is done, I iterated over the buffer and whenever I found a white pixel, I set the correct color on the main image's corresponding pixel. Efficient? Maybe not. Simple, yes. hth, –natevw

« previous php.gd.devel (#261) next »