469,917 Members | 1,881 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

PIL ImageDraw line not long enough

I've resorted to actually drawing all of the characters of the alphabet on a
graph to avoid having to drag around font files. It's mostly just uppercase
characters, so it's not too bad.

But I noticed that some of the line segments have to be extended one pixel
longer than they should be in order for the last pixel to show up.

The character cells are 6 pixels wide by 8 pixels high. An "L" is drawn
with

Graph.line((x,y, x,y+7, x+5,y+7), Color)

where the starting x and y are supplied to the function. An L works OK, but
to get a "T" to look right I have to do

Graph.line((x+1,y, x+5,y), Color)
Graph.line((x+3,y, x+3,y+8), Color)

I have to extend the vertical line to y+8, instead of y+7 to get the line
segment to be drawn long enough. This is on Linux, Solaris, 2.x versions of
Python, 1.1.5 version of PIL, and on Windows with the latest of everything.
Am I missing a setting somewhere?

Thanks!

Bob


Mar 30 '06 #1
3 2181
Bob Greschke wrote
I've resorted to actually drawing all of the characters of the alphabet on a
graph to avoid having to drag around font files. It's mostly just uppercase
characters, so it's not too bad.

But I noticed that some of the line segments have to be extended one pixel
longer than they should be in order for the last pixel to show up.

The character cells are 6 pixels wide by 8 pixels high. An "L" is drawn
with

Graph.line((x,y, x,y+7, x+5,y+7), Color)

where the starting x and y are supplied to the function. An L works OK, but
to get a "T" to look right I have to do

Graph.line((x+1,y, x+5,y), Color)
Graph.line((x+3,y, x+3,y+8), Color)

I have to extend the vertical line to y+8, instead of y+7 to get the line
segment to be drawn long enough. This is on Linux, Solaris, 2.x versions of
Python, 1.1.5 version of PIL, and on Windows with the latest of everything.
Am I missing a setting somewhere?


Some drawing APIs (e.g. Windows GDI) draw lines including the starting
point but excluding the end point: I think the reason is that this way,
if you draw a series of connected lines (like in your "L" case), no
pixel gets drawn twice (this is important if you use colors with alpha
channels, or line patterns).

Mar 30 '06 #2
Bob Greschke wrote:
I have to extend the vertical line to y+8, instead of y+7 to get the line
segment to be drawn long enough. This is on Linux, Solaris, 2.x versions of
Python, 1.1.5 version of PIL, and on Windows with the latest of everything.
Am I missing a setting somewhere?


I recently got another bug reported that talked about the same thing, so
it's probably a bug in 1.1.5 that nobody has noticed before.

(as nikie mentions, the low-level line segment drawer avoids drawing over-
lapping points, but the "line" wrapper should add the last pixel)

</F>

Mar 31 '06 #3
"Fredrik Lundh" <fr*****@pythonware.com> wrote in message
news:ma***************************************@pyt hon.org...
Bob Greschke wrote:
I have to extend the vertical line to y+8, instead of y+7 to get the line
segment to be drawn long enough. This is on Linux, Solaris, 2.x versions
of
Python, 1.1.5 version of PIL, and on Windows with the latest of
everything.
Am I missing a setting somewhere?


I recently got another bug reported that talked about the same thing, so
it's probably a bug in 1.1.5 that nobody has noticed before.

(as nikie mentions, the low-level line segment drawer avoids drawing over-
lapping points, but the "line" wrapper should add the last pixel)

</F>


Hey! It's not ME for once. :) It seems to only happen with lines that have
a vertical-ness to them (straight up-down or diagonal). It doesn't seem to
happen when the line segment is just horizontal.

These are the characters that I am drawing

www.greschke.com/unlinked/images/graphs.png

It works really well.

Thanks!

Bob

Apr 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Max M | last post: by
8 posts views Thread by nephish | last post: by
6 posts views Thread by Edd Dawson | last post: by
reply views Thread by alexandre_irrthum | last post: by
1 post views Thread by alexandre_irrthum | last post: by
1 post views Thread by aljosa | last post: by
3 posts views Thread by Daniel Mark | last post: by
6 posts views Thread by Bryan Parkoff | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.