PIL ImageDraw line not long enough

nikie n.estner at gmx.de
Thu Mar 30 18:18:48 EST 2006


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




More information about the Python-list mailing list