[Image-SIG] PIL 1.1.5 polygon filling off by one vertical pixel, alpha blended drawing?

LML TeXSatz at uni-bremen.de
Wed May 25 23:15:12 CEST 2005

Hi all,
the ImageDraw.Draw.polygon function does not draw as I expect it.
Deep down in the C-code some Floor, Ceil and +0.5 seem to combine
for a strange effect.

1. Any suggestions to actually draw within the outline only?
2. Why can't I draw with alpha-blending (it seems like I
    have to im.paste to achieve this -- so inefficient...)
3. Do I have to destruct the Draw instance with del explicitly
    (like it's done in the example code)
    or is the implicit destruction enough to get it freed?
4. Is ImagePath.Path more efficient or just syntactic sugar?

Code to show the effect:

import Image, ImageDraw

def save(image, fname='save.png'):
     W = file(fname, 'wb')

def testpic():
     """Test polygon, line etc. drawing."""
     im = Image.new('RGBA', (100,100))
     D = ImageDraw.Draw(im)
     fi=(0xbf, 0xbf, 0xbf, 0x7f)
     D.line([(39,0),(39,100)],fill=fi) #vertical lines
     D.line([(0,39),(100,39)],fill=fi) #horizontal lines
     fi=(0xbf, 0x00, 0x00, 0x7f) #red
     ou=(0x7f, 0x00, 0x00, 0x7f)
     D.polygon([(40, 40), (40, 60), (60, 60), (60, 40)], fill=fi, 
     D.polygon([(10, 10), (10, 30), (30, 30), (30, 10)], fill=fi, 
     D.polygon([(70, 10), (71, 30), (91, 30), (90, 10)], fill=fi, 
     fi=(0x00, 0xbf, 0x00, 0x7f) #green
     ou=(0x00, 0x7f, 0x00, 0x7f)
     D.polygon([(20, 70), (10, 80), (20, 90), (30, 80)], fill=fi, 
     D.polygon([(81, 70), (70, 80), (80, 90), (91, 80)], fill=fi, 
     D.polygon([(50, 40), (40, 50), (50, 60), (60, 50)], fill=fi, 
     D.point([(0, 0)],fill='red') #mark origin

the resulting save.png is attached -- hopefully small enough ;-)

I intend to use the polygon function to draw land/coastlines
combined with satellite (point) data -- that's where the alpha
blending is supposed to enter the picture...

Thanks for your help.
\bye Lothar (Meyer-Lerbs, Bremen, Germany)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: save.png
Type: image/png
Size: 1780 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20050525/ec945c03/save.png

More information about the Image-SIG mailing list