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

Apply transparency to P images in ImageTk.PhotoImage #6559

Merged
merged 1 commit into from Sep 24, 2022
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
7 changes: 7 additions & 0 deletions Tests/test_imagetk.py
Expand Up @@ -69,6 +69,13 @@ def test_photoimage():
assert_image_equal(reloaded, im.convert("RGBA"))


def test_photoimage_apply_transparency():
with Image.open("Tests/images/pil123p.png") as im:
im_tk = ImageTk.PhotoImage(im)
reloaded = ImageTk.getimage(im_tk)
assert_image_equal(reloaded, im.convert("RGBA"))


def test_photoimage_blank():
# test a image using mode/size:
for mode in TK_MODES:
Expand Down
1 change: 1 addition & 0 deletions src/PIL/ImageTk.py
Expand Up @@ -107,6 +107,7 @@ def __init__(self, image=None, size=None, **kw):
mode = image.mode
if mode == "P":
# palette mapped data
image.apply_transparency()
image.load()
try:
mode = image.palette.mode
Expand Down