libGD

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.

Tasklist

FS#100 — spurious horizontal line drawn by gdImageFilledPolygon; fix attached

Attached to Project — libGD
Opened by Ducky Sherwood (duckysherwood) - Thursday, 19 July 2007, 08:20 GMT+2
Last edited by Takeshi Abe (Takeshi) - Tuesday, 19 January 2010, 10:05 GMT+2
Task Type Bug Report
Category General
Status Closed
Assigned To Pierre Joye (Pierre)
Operating System All
Severity Low
Priority Normal
Reported Version 2.0.35
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

There 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.

This task depends upon

Closed by  Takeshi Abe (Takeshi)
Tuesday, 19 January 2010, 10:05 GMT+2
Reason for closing:  Fixed
Additional comments about closing:  Thanks for your comments.

It is fixed in both gd-libgd and gd-libgd-20.
Comment by Ducky Sherwood (duckysherwood) - Thursday, 19 July 2007, 18:09 GMT+2

Hmm, I thought I attached the files already, but I don't see them. Here they are (again?)

Comment by Ducky Sherwood (duckysherwood) - Thursday, 19 July 2007, 20:51 GMT+2

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.

Comment by Ducky Sherwood (duckysherwood) - Tuesday, 07 August 2007, 06:48 GMT+2

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.

Comment by Pierre Joye (Pierre) - Tuesday, 07 August 2007, 07:06 GMT+2

Thanks for the patch!

I will check this bug later this week.

Comment by Ducky Sherwood (duckysherwood) - Thursday, 27 November 2008, 21:32 GMT+2

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..)

Comment by Tatsuya Noda (tanoda) - Tuesday, 13 October 2009, 07:39 GMT+2

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.

Comment by Susmith (susmith) - Wednesday, 13 January 2010, 15:23 GMT+2

Hi

  I too have same problem. I am using language perl. I dont know how I will apply the patch, that was provided above.

Can any one please help me on this. OS : Ubuntu Language : Perl

Loading...