Skip to content

Commit

Permalink
Merge pull request #7018 from radarhere/apng
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 23, 2023
2 parents 3d4a6f7 + 0966293 commit 745f540
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Binary file added Tests/images/blend_transparency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def test_apng_blend():
assert im.getpixel((64, 32)) == (0, 255, 0, 255)


def test_apng_blend_transparency():
with Image.open("Tests/images/blend_transparency.png") as im:
im.seek(1)
assert im.getpixel((0, 0)) == (255, 0, 0)


def test_apng_chunk_order():
with Image.open("Tests/images/apng/fctl_actl.png") as im:
im.seek(im.n_frames - 1)
Expand Down
10 changes: 7 additions & 3 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,13 @@ def load_end(self):
else:
if self._prev_im and self.blend_op == Blend.OP_OVER:
updated = self._crop(self.im, self.dispose_extent)
self._prev_im.paste(
updated, self.dispose_extent, updated.convert("RGBA")
)
if self.im.mode == "RGB" and "transparency" in self.info:
mask = updated.convert_transparent(
"RGBA", self.info["transparency"]
)
else:
mask = updated.convert("RGBA")
self._prev_im.paste(updated, self.dispose_extent, mask)
self.im = self._prev_im
if self.pyaccess:
self.pyaccess = None
Expand Down

0 comments on commit 745f540

Please sign in to comment.