Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not alter pixels outside mask when drawing text on an image with transparency #5434

Merged
merged 1 commit into from
May 9, 2021

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Apr 24, 2021

Resolves #5431

The issue reports that drawing text onto an RGBA image, and then removing the transparency by converting that image to L, a rectangle around the text has been affected by the draw operation. Testing, this was not the case before #4566.

Why is this the case?

When drawing text onto an image, a mask is used.

mask

#4566 changed how the mask was blended into an image so that if the image was transparent, it's RGB values were not considered - so that black transparent pixels do not combine with white opaque text to give gray pixels. Comparing the output of the test from that PR,

____ Without PR 4566 With PR 4566
RGBA RGBA RGBA

However, it turns out that this was applied too broadly, ignoring the RGB values the whole of the mask area - if the above results are converted to L,

____ Without PR 4566 With PR 4566
L L L

It should only be applied to the parts where the mask is not zero.

____ With This PR
RGBA RGBA
L L

@hugovk hugovk merged commit 649eaae into python-pillow:master May 9, 2021
@radarhere radarhere deleted the text_alpha branch May 9, 2021 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drawing text on image works incorrectly if the image opacity is 0
2 participants