Skip to content

Commit

Permalink
fixed apply_background_color
Browse files Browse the repository at this point in the history
to remove partial transparency too if the specified background color is fully solid
  • Loading branch information
lukas-buergi committed Jan 27, 2025
1 parent 37bbf63 commit 06c6c57
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions rembg/bg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 06c6c57

Please sign in to comment.