Commit b5ee0509 authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): add alpha check for load image function

parent 75667b88
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ ImageTyping = Union[str, PathLike, bytes, bytearray, BinaryIO, Image.Image]
MultiImagesTyping = Union[ImageTyping, List[ImageTyping], Tuple[ImageTyping, ...]]


def _has_alpha_channel(image: Image.Image) -> bool:
    return any(band in {'A', 'a'} for band in image.getbands())


def load_image(image: ImageTyping, mode=None, force_background: Optional[str] = 'white'):
    """
    Loads the image from the provided source and applies necessary transformations.
@@ -47,7 +51,7 @@ def load_image(image: ImageTyping, mode=None, force_background: Optional[str] =
    else:
        raise TypeError(f'Unknown image type - {image!r}.')

    if force_background is not None:
    if _has_alpha_channel(image) and force_background is not None:
        image = add_background_for_rgba(image, force_background)

    if mode is not None and image.mode != mode: