Merge pull request #717 from lukas-buergi/fix_transparency

fixed apply_background_color leaving partial transparency when it shouldn't
This commit is contained in:
Daniel Gatis 2025-01-30 09:26:28 -03:00 committed by GitHub
commit 519d3e2c88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -175,9 +175,8 @@ def apply_background_color(img: PILImage, color: Tuple[int, int, int, int]) -> P
Returns: Returns:
PILImage: The modified image with the background color applied. PILImage: The modified image with the background color applied.
""" """
r, g, b, a = color background = Image.new("RGBA", img.size, tuple(color))
colored_image = Image.new("RGBA", img.size, (r, g, b, a)) colored_image = Image.alpha_composite(background, img)
colored_image.paste(img, mask=img)
return colored_image return colored_image