[Image-SIG] Unexpected behavior of ImageDraw. polygon ?

Dave Cowden dave.cowden at gmail.com
Wed Mar 30 22:45:35 CEST 2011


Hello, everyone:

I have been really struggling with a PIL issue, and I'm hoping someone
else has experienced the behavior I am seeing.

My goal is to use ImageDraw().polygon to produce _only_ the filling,
and to draw the border of the polygon in either transparent or in the
background color.

When I attempt to do this, an odd extra line of pixels appears outside
the boundary.

The code below draws a simple polygon with a white border and black
fill, which works as expected.

The second code draws the same polygon with a black border and a white
fill. my expected result is to get a white triangle that 'fits inside'
the first one. It almost works, but there is an extra line of pixels
along the upper-right border.

The resulting pictures are attached.

Here is my code:

from PIL import Image,ImageDraw

if __name__=='__main__':
	i = Image.new('L',(50,50), 0 );
	ImageDraw.Draw(i).polygon([(10,10),(20,20),(10,20) ],outline=255, fill=0);
	i.save("c:\\temp\\freak1.bmp",format="bmp");
	
	i = Image.new('L',(50,50), 0 );
	ImageDraw.Draw(i).polygon([(10,10),(20,20),(10,20) ],outline=0, fill=255);
	i.save("c:\\temp\\freak2.bmp",format="bmp");

Can anyone help me understand what i'm doing wrong? Help is much appreciated!
Python 2.6.6, Windows, PIL version 1.1.7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: freak2.bmp
Type: image/bmp
Size: 3678 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20110330/186c6d82/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: freak1.bmp
Type: image/bmp
Size: 3678 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20110330/186c6d82/attachment-0003.bin>


More information about the Image-SIG mailing list