Loading imgutils/data/image.py +5 −1 Original line number Diff line number Diff line Loading @@ -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', 'P'} 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. Loading Loading @@ -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: Loading imgutils/detect/text.py +1 −1 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ def detect_text(image: ImageTyping, model: str = _DEFAULT_MODEL, threshold: floa This function is deprecated, and it will be removed from imgutils in the future. Please migrate to :func:`imgutils.ocr.detect_text_with_ocr` as soon as possible. """ image = load_image(image) image = load_image(image, mode='RGB') if max_area_size is not None and image.width * image.height >= max_area_size ** 2: r = ((image.width * image.height) / (max_area_size ** 2)) ** 0.5 new_width, new_height = int(image.width / r), int(image.height / r) Loading Loading
imgutils/data/image.py +5 −1 Original line number Diff line number Diff line Loading @@ -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', 'P'} 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. Loading Loading @@ -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: Loading
imgutils/detect/text.py +1 −1 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ def detect_text(image: ImageTyping, model: str = _DEFAULT_MODEL, threshold: floa This function is deprecated, and it will be removed from imgutils in the future. Please migrate to :func:`imgutils.ocr.detect_text_with_ocr` as soon as possible. """ image = load_image(image) image = load_image(image, mode='RGB') if max_area_size is not None and image.width * image.height >= max_area_size ** 2: r = ((image.width * image.height) / (max_area_size ** 2)) ** 0.5 new_width, new_height = int(image.width / r), int(image.height / r) Loading