Skip to content

Commit

Permalink
Merge pull request #8443 from radarhere/apng_p_transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Oct 6, 2024
2 parents 01bb78a + b77cd00 commit 838e0fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def test_apng_mode() -> None:
assert im.mode == "P"
im.seek(im.n_frames - 1)
im = im.convert("RGBA")
assert im.getpixel((0, 0)) == (255, 0, 0, 0)
assert im.getpixel((64, 32)) == (255, 0, 0, 0)
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
assert im.getpixel((64, 32)) == (0, 255, 0, 255)

with Image.open("Tests/images/apng/mode_palette_1bit_alpha.png") as im:
assert im.mode == "P"
Expand Down
6 changes: 6 additions & 0 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,12 @@ def load_end(self) -> None:
"RGBA", self.info["transparency"]
)
else:
if self.im.mode == "P" and "transparency" in self.info:
t = self.info["transparency"]
if isinstance(t, bytes):
updated.putpalettealphas(t)
elif isinstance(t, int):
updated.putpalettealpha(t)
mask = updated.convert("RGBA")
self._prev_im.paste(updated, self.dispose_extent, mask)
self.im = self._prev_im
Expand Down

0 comments on commit 838e0fb

Please sign in to comment.