diff --git a/Tests/test_features.py b/Tests/test_features.py index 40466082f7a..cb8fd8688c9 100644 --- a/Tests/test_features.py +++ b/Tests/test_features.py @@ -46,6 +46,18 @@ def test(name: str, function: Callable[[str], str | None]) -> None: test(feature, features.version_feature) +def test_webp_transparency() -> None: + assert features.check("transp_webp") == features.check_module("webp") + + +def test_webp_mux() -> None: + assert features.check("webp_mux") == features.check_module("webp") + + +def test_webp_anim() -> None: + assert features.check("webp_anim") == features.check_module("webp") + + @skip_unless_feature("libjpeg_turbo") def test_libjpeg_turbo_version() -> None: version = features.version("libjpeg_turbo") diff --git a/docs/reference/features.rst b/docs/reference/features.rst index 26c8ab8cd69..fcff9673567 100644 --- a/docs/reference/features.rst +++ b/docs/reference/features.rst @@ -57,6 +57,9 @@ Support for the following features can be checked: * ``raqm``: Raqm library, required for ``ImageFont.Layout.RAQM`` in :py:func:`PIL.ImageFont.truetype`. Run-time version number is available for Raqm 0.7.0 or newer. * ``libimagequant``: (compile time) ImageQuant quantization support in :py:func:`PIL.Image.Image.quantize`. Run-time version number is available. * ``xcb``: (compile time) Support for X11 in :py:func:`PIL.ImageGrab.grab` via the XCB library. +* ``transp_webp``: Deprecated. Always ``True`` if WebP module is installed. +* ``webp_mux``: Deprecated. Always ``True`` if WebP module is installed. +* ``webp_anim``: Deprecated. Always ``True`` if WebP module is installed. .. autofunction:: PIL.features.check_feature .. autofunction:: PIL.features.version_feature diff --git a/docs/releasenotes/11.0.0.rst b/docs/releasenotes/11.0.0.rst index 964423ae035..aa5b06a627b 100644 --- a/docs/releasenotes/11.0.0.rst +++ b/docs/releasenotes/11.0.0.rst @@ -43,10 +43,13 @@ similarly removed. Deprecations ============ -TODO -^^^^ +WebP Features Test +^^^^^^^^^^^^^^^^^^ -TODO +The following features ``features.check("transp_webp")``, +``features.check("webp_mux")``, and ``features.check("webp_anim")`` are now +always ``True`` if the WebP module is installed and sohuld not be used. +These checks wil be removed in Pillow 12.0.0 (2025-10-15). API Changes =========== diff --git a/src/PIL/features.py b/src/PIL/features.py index bbf7c641b43..f594a2cdc4a 100644 --- a/src/PIL/features.py +++ b/src/PIL/features.py @@ -7,6 +7,7 @@ from typing import IO import PIL +from PIL import _deprecate from . import Image @@ -119,6 +120,9 @@ def get_supported_codecs() -> list[str]: features = { + "webp_anim": ("PIL._webp", True, None), + "webp_mux": ("PIL._webp", True, None), + "transp_webp": ("PIL._webp", True, None), "raqm": ("PIL._imagingft", "HAVE_RAQM", "raqm_version"), "fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"), "harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"), @@ -144,7 +148,11 @@ def check_feature(feature: str) -> bool | None: try: imported_module = __import__(module, fromlist=["PIL"]) - return getattr(imported_module, flag) + if isinstance(flag, str): + return getattr(imported_module, flag) + else: + _deprecate.deprecate(f'check_feature("{feature}")', 12) + return flag except ModuleNotFoundError: return None except ImportError as ex: