Skip to content

Commit

Permalink
Changed has_transparency_data() to property
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Sep 26, 2023
1 parent 1c30809 commit faea2bb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Tests/test_image.py
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/Image.rst
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/PIL/Image.py
Expand Up @@ -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
Expand Down

0 comments on commit faea2bb

Please sign in to comment.