diff --git a/Tests/test_image.py b/Tests/test_image.py index 487035a3ef9..b9c57770c70 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -909,27 +909,27 @@ def test_zero_tobytes(self, size): def test_has_transparency_data(self): for mode in ("1", "L", "P", "RGB"): im = Image.new(mode, (1, 1)) - assert not im.has_transparency_data() + assert not im.has_transparency_data for mode in ("LA", "La", "PA", "RGBA", "RGBa"): im = Image.new(mode, (1, 1)) - assert im.has_transparency_data() + assert im.has_transparency_data # P mode with "transparency" info with Image.open("Tests/images/first_frame_transparency.gif") as im: assert "transparency" in im.info - assert im.has_transparency_data() + assert im.has_transparency_data # RGB mode with "transparency" info with Image.open("Tests/images/rgb_trns.png") as im: assert "transparency" in im.info - assert im.has_transparency_data() + assert im.has_transparency_data # P mode with RGBA palette im = Image.new("RGBA", (1, 1)).convert("P") assert im.mode == "P" assert im.palette.mode == "RGBA" - assert im.has_transparency_data() + assert im.has_transparency_data def test_apply_transparency(self): im = Image.new("P", (1, 1)) diff --git a/docs/reference/Image.rst b/docs/reference/Image.rst index ae8f923cb7a..e356469b673 100644 --- a/docs/reference/Image.rst +++ b/docs/reference/Image.rst @@ -195,7 +195,7 @@ This helps to get the bounding box coordinates of the input image:: .. automethod:: PIL.Image.Image.getpalette .. automethod:: PIL.Image.Image.getpixel .. automethod:: PIL.Image.Image.getprojection -.. automethod:: PIL.Image.Image.has_transparency_data +.. autoproperty:: PIL.Image.Image.has_transparency_data .. automethod:: PIL.Image.Image.histogram .. automethod:: PIL.Image.Image.paste .. automethod:: PIL.Image.Image.point diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 842e5db56ea..244d2e43520 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1531,6 +1531,7 @@ def getpalette(self, rawmode="RGB"): rawmode = mode return list(self.im.getpalette(mode, rawmode)) + @property def has_transparency_data(self) -> bool: """ Determine if an image has transparency data, whether in the form of an diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 86169b78085..fa34769e77f 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -332,7 +332,7 @@ def _save(im, fp, filename): exact = 1 if im.encoderinfo.get("exact") else 0 if im.mode not in _VALID_WEBP_LEGACY_MODES: - im = im.convert("RGBA" if im.has_transparency_data() else "RGB") + im = im.convert("RGBA" if im.has_transparency_data else "RGB") data = _webp.WebPEncode( im.tobytes(),