INNER CODE UNIT · Python
clamp_alpha
KennethJAllen/proper-pixel-art · proper_pixel_art/colors.py:85
def clamp_alpha(
image: Image.Image,
alpha_threshold: int = ALPHA_THRESHOLD,
mode: str = "RGB",
background_hex: str | None = None,
limit: int = _DEFAULTS.top_colors_limit,
thumbnail_size: tuple[int, int] = _DEFAULTS.thumbnail_size,
background_candidates: list[RGB] | None = None,
) -> Image.Image:
"""
Replace pixels with alpha < threshold by a background color.
If background_hex is None, choose a color far from the most common image colors.
mode: 'RGB' or 'L'
"""
if mode not in ("RGB", "L"):
raise ValueError("mode must be 'RGB' or 'L'")
if background_hex is None: