Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep transparency when converting from P to LA or PA #5606

Merged
merged 1 commit into from Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions Tests/test_image_convert.py
Expand Up @@ -100,18 +100,22 @@ def test_trns_p(tmp_path):
# ref https://github.com/python-pillow/Pillow/issues/664


def test_trns_p_rgba():
@pytest.mark.parametrize("mode", ("LA", "PA", "RGBA"))
def test_trns_p_transparency(mode):
# Arrange
im = hopper("P")
im.info["transparency"] = 128

# Act
im_rgba = im.convert("RGBA")
converted_im = im.convert(mode)

# Assert
assert "transparency" not in im_rgba.info
# https://github.com/python-pillow/Pillow/issues/2702
assert im_rgba.palette is None
assert "transparency" not in converted_im.info
if mode == "PA":
assert converted_im.palette is not None
else:
# https://github.com/python-pillow/Pillow/issues/2702
assert converted_im.palette is None


def test_trns_l(tmp_path):
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/Image.py
Expand Up @@ -1005,7 +1005,7 @@ def convert_transparency(m, v):
trns_im = trns_im.convert("RGB")
trns = trns_im.getpixel((0, 0))

elif self.mode == "P" and mode == "RGBA":
elif self.mode == "P" and mode in ("LA", "PA", "RGBA"):
t = self.info["transparency"]
delete_trns = True

Expand Down