PIL ImageDraw line not long enough

B

Bob Greschke

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
 
N

nikie

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

Fredrik Lundh

Bob said:
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>
 
B

Bob Greschke

Fredrik Lundh said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,162
Latest member
DarwinMaku

Latest Threads

Top