From 06c6c5755969de5fdfeb06787424e709e27cd627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=BCrgi?= Date: Mon, 27 Jan 2025 12:14:09 +0100 Subject: [PATCH] fixed apply_background_color to remove partial transparency too if the specified background color is fully solid --- rembg/bg.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rembg/bg.py b/rembg/bg.py index 431636b..2dc2af3 100644 --- a/rembg/bg.py +++ b/rembg/bg.py @@ -175,9 +175,8 @@ def apply_background_color(img: PILImage, color: Tuple[int, int, int, int]) -> P Returns: PILImage: The modified image with the background color applied. """ - r, g, b, a = color - colored_image = Image.new("RGBA", img.size, (r, g, b, a)) - colored_image.paste(img, mask=img) + background = Image.new("RGBA", img.size, tuple(color)) + colored_image = Image.alpha_composite(background, img) return colored_image