ImageDraw line inconsistent ? (repost)

alexandre_irrthum at yahoo.com alexandre_irrthum at yahoo.com
Fri Apr 7 09:39:15 EDT 2006


Hi there,

Sorry to repost this, but I didn't get any answer one month ago. In
essence, it seems that the ImageDraw line function draws lines one
pixel shorter in some circumstances. This could be very annoying for
some applications where precise geometry does matter.

Below I test this function on a 3x3 image and show schematic
representations of obtained images (where o means a drawn pixel)

import Image, ImageDraw
im = Image.new("L", (3,3))
draw = ImageDraw.Draw(im)
draw.line((0,0,2,2), fill=255)
im.tostring()

Gives:

o--
-o-
---

So the last pixel of the line is not drawn.

Similarly, draw.line((0,2,2,0), fill=255) gives:

---
-o-
o--

And draw.line((1,0,1,2), fill=255) gives:

-o-
-o-
---

But, surprisingly, draw.line((0,1,2,1), fill=255) gives:

---
ooo
---

Where the last pixel of the line -is- drawn, as I expected it would be
for all lines.

This seems to be true for various image sizes and line angles: the last
pixel is never drawn unless the line is horizontal.

Any clues ?

Thanks

alex




More information about the Python-list mailing list