alexeyprog
alexeyprog

Reputation: 816

Python `aggdraw` module bug (?): visible alpha channel

Imagine simple script:

from PIL import Image
from aggdraw import Draw, Brush

im = Image.new("RGBA", (600, 600), (0, 0, 0, 0))
draw = Draw(im)

brush = Brush("yellow")

draw.polygon(
             (
              50, 50,
              550, 60,
              550, 550,
              60, 550,
             ),
             None, brush
            )

draw.flush()
im.save("2.png")

And the result: enter image description here

(Sorry for big size but that is more clearly)

And the problem: Can you see non-yellow and non-white edges? This is the alpha-channel or something.

When I trying to do this only with PIL's Draw object - it looks clearly and good but not anti-aliased.

But with aggdraw's Draw object it looks anti-aliased but with that ugly dirty edges.

I need exactly polygons with non-standard side angles. Simple box is not what I want.

Please, help me with some good optimistic answer how to solve this problem.

Upvotes: 1

Views: 424

Answers (1)

Todd
Todd

Reputation: 6179

It's because your background is black, but transparent. If you set your image background to white, you don't get the visible edges. Either transparent or solid white works in my simple tests.

Try these values:

transBlack = (0, 0, 0, 0)         # shows your example with visible edges
solidBlack = (0, 0, 0, 255)       # shows shape on a black background
transWhite = (255, 255, 255, 0)
solidWhite = (255, 255, 255, 255)

im = Image.new("RGBA", (600, 600), solidWhite)

Upvotes: 1

Related Questions