mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Changed has_transparency_data() to property
This commit is contained in:
parent
1c30809245
commit
e27d7a6f84
|
@ -909,27 +909,27 @@ class TestImage:
|
|||
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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1531,6 +1531,7 @@ class Image:
|
|||
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
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user