Skip to content

Polygon not rendering 'cleanly' - fill sometimes appears outside expected boundaries #6414

@Tom1827

Description

@Tom1827

What did you do?

rendered polygons

What did you expect to happen?

accurate rednering of polygons

What actually happened?

'dirty' polygon rendering, with drawing outside of expected boundaries

this is the polygon rendered by Pillow; you can clearly see the fill color (blue) outside of the expected boundary lines (white):
test

this is a polygon, using precisely the same data, rendered by pysdl2:
test_pystl2

What versions of Pillow and Python are you using?

Pillow 9.1.1
Python 3.10.2 (on Windows)

Code to reproduce:

from PIL import Image, ImageDraw

i = Image.new("RGB", (1050, 1068))
draw = ImageDraw.Draw(i)

test_polygon = [(30.0, 629.4507134752477), (50.0, 629.8565139892041), (70.0, 627.2543706746618), 
                (90.0, 626.0154710958213), (110.0, 626.011874242351), (130.0, 625.3440687206069), 
                (150.0, 625.664018531622), (170.0, 625.4978763181073), (190.0, 626.8082520616501),
                (210.0, 628.4793899572998), (230.0, 625.5727005531411), (250.0, 626.6852232204809), 
                (270.0, 629.2271456013137), (290.0, 629.674604313272), (310.0, 629.6868878544574), 
                (330.0, 629.6868878544574), (350.0, 629.5207747265167), (370.0, 626.9244799578914), 
                (390.0, 625.4966243597871), (410.0, 627.1466394082299), (430.0, 626.8563010422029), 
                (450.0, 625.9732816358337), (470.0, 626.0223664538509), (490.0, 625.9939078255982), 
                (510.0, 626.3296698337327), (530.0, 628.102891777509), (550.0, 627.7136916475783), 
                (570.0, 627.7000106564611), (590.0, 628.2368838860209), (610.0, 628.9263631533747),
                (630.0, 629.4478207168099), (650.0, 629.529289231639), (670.0, 629.5638852462581), 
                (690.0, 629.6030138047543), (710.0, 626.5579731233461), (730.0, 625.0519611728187), 
                (750.0, 625.0578344827394), (770.0, 625.3224042542365), (790.0, 626.3760735193364),
                (810.0, 628.1560246482019), (830.0, 628.6247994798618), (850.0, 628.2015120730098), 
                (870.0, 627.6041293694293), (890.0, 626.6221235932012), (910.0, 625.696843383893),
                (930.0, 626.1766968392732), (950.0, 626.2595546558532), (970.0, 625.7111921762546),
                (990.0, 625.4764505087265), (1010.0, 626.4968501568546), (1030.0, 629.9504926228511),
                (1030.0, 630.0495073771489), (1010.0, 633.5031498431454), (990.0, 634.5235494912735),
                (970.0, 634.2888078237454), (950.0, 633.7404453441468), (930.0, 633.8233031607268),
                (910.0, 634.303156616107), (890.0, 633.3778764067988), (870.0, 632.3958706305707),
                (850.0, 631.7984879269902), (830.0, 631.3752005201382), (810.0, 631.8439753517981),
                (790.0, 633.6239264806636), (770.0, 634.6775957457635), (750.0, 634.9421655172606),
                (730.0, 634.9480388271813), (710.0, 633.4420268766539), (690.0, 630.3969861952457),
                (670.0, 630.4361147537419), (650.0, 630.470710768361), (630.0, 630.5521792831901),
                (610.0, 631.0736368466253), (590.0, 631.7631161139791), (570.0, 632.2999893435389),
                (550.0, 632.2863083524217), (530.0, 631.897108222491), (510.0, 633.6703301662673),
                (490.0, 634.0060921744018), (470.0, 633.9776335461491), (450.0, 634.0267183641663),
                (430.0, 633.1436989577971), (410.0, 632.8533605917701), (390.0, 634.5033756402129),
                (370.0, 633.0755200421086), (350.0, 630.4792252734833), (330.0, 630.3131121455426),
                (310.0, 630.3131121455426), (290.0, 630.325395686728), (270.0, 630.7728543986863),
                (250.0, 633.3147767795191), (230.0, 634.4272994468589), (210.0, 631.5206100427002),
                (190.0, 633.1917479383499), (170.0, 634.5021236818927), (150.0, 634.335981468378),
                (130.0, 634.6559312793931), (110.0, 633.988125757649), (90.0, 633.9845289041787),
                (70.0, 632.7456293253382), (50.0, 630.1434860107959), (30.0, 630.5492865247523)]

draw.polygon(test_polygon, fill=(0, 0, 255, 255), outline=(255, 255, 255, 0))

i.save('test.png')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions