GD is an open source code library for the dynamic creation of images by programmers. GD is written in C, and “wrappers” are available for Perl, PHP and other languages. GD creates PNG, JPEG and GIF images, among other formats. GD is commonly used to generate charts, graphics, thumbnails, and most anything else, on the fly. While not restricted to use on the web, the most common applications of GD involve web site development.
See the GD website for more informations.
FS#100 — spurious horizontal line drawn by gdImageFilledPolygon; fix attached
Opened by Ducky Sherwood (duckysherwood) - Thursday, 19 July 2007, 08:20 GMT+1
Last edited by Takeshi Abe (Takeshi) - Tuesday, 19 January 2010, 10:05 GMT+1
|
DetailsThere is a bug in gdImageFilledPolygon such that you can get spurious horizontal lines. I’ve attached fix for it and a test case that demonstrates it. gdImageFilledPolygon works by iteratively drawing horizontal lines between the borders of the polygon. To do this, it interpolates the x-value for a given y-value, based on the positions of two connected vertices. Then, it sorts the x-values (for that given y-value) and draws lines between the first and second x-value, third and fourth, etc. (Why does it sort? To deal with cases where the polygon is shaped such that there is a gap in the horizontal line. Imagine, for example, a “V” shape – a horizontal slice near the top would give two colored pieces with a non-colored piece in between them.) Unfortunately, it is possible to get conditions where you have an *odd* number of x-values that intersect a given y-value. Thus when gdImageFilledPolygon tries to draw a horizontal line between x[i] and x[i+1], the x[i+1] is garbage (usually 0 for me, YMMV). To fix this, I checked for odd-numbers of intercepts. If it was odd, I added an intercept, making x[i+1] = x[i]. This means drawing a spurious dot, but that seemed safer than taking one intercept away. |
Tuesday, 19 January 2010, 10:05 GMT+1
Reason for closing: Fixed
Additional comments about closing: Thanks for your comments.
It is fixed in both gd-libgd and gd-libgd-20.
Hmm, I thought I attached the files already, but I don't see them. Here they are (again?)
Whoops, I haven't completely fixed it. I've got a polyon that looks sort of like "^" and it's failing to draw part of the bottom line. I'm looking into it.
Okay, I believe I have a better patch.
There are some cases where two vertices in a row will have the same y-coordinate. When calculating the intercept of the line, it didn't calculate the intercept (which is understandable, since rise/run is infinity when run is 0!)
I made it so that if y1=y2, then it just uses x2 as the y-intercept. That seems to get rid of all my horizontal line problems.
I have attached a patch and a test case.
Thanks for the patch!
I will check this bug later this week.
Pierre –
Did you ever get a chance to confirm/fix this?
I'd really like to use the gd that my ISP uses, instead of having to statically compile it in. (I'd like to use gd with PHP, for example.) I can't do that as long as the bug persists in gd... (or at least I don't know how to point my PHP to a different version of gd..)
Pierre –
I attached results of bug4.c, with before/after appling lineBugFix.patch.
According to bug4.c's comment, it is not completely fixed patch, but seems to work better.
Please check two results, and make this better?
Thanks.
Hi
Can any one please help me on this. OS : Ubuntu Language : Perl