Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_apng_blend() -> None:
with Image.open("Tests/images/apng/blend_op_over_near_transparent.png") as im:
assert isinstance(im, PngImagePlugin.PngImageFile)
im.seek(im.n_frames - 1)
assert im.getpixel((0, 0)) == (0, 255, 0, 97)
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
assert im.getpixel((64, 32)) == (0, 255, 0, 255)


Expand Down Expand Up @@ -323,8 +323,8 @@ def test_apng_mode() -> None:
assert isinstance(im, PngImagePlugin.PngImageFile)
assert im.mode == "RGBA"
im.seek(im.n_frames - 1)
assert im.getpixel((0, 0)) == (0, 0, 128, 191)
assert im.getpixel((64, 32)) == (0, 0, 128, 191)
assert im.getpixel((0, 0)) == (0, 0, 128, 255)
assert im.getpixel((64, 32)) == (0, 0, 128, 255)

with Image.open("Tests/images/apng/mode_grayscale.png") as im:
assert isinstance(im, PngImagePlugin.PngImageFile)
Expand All @@ -337,8 +337,8 @@ def test_apng_mode() -> None:
assert isinstance(im, PngImagePlugin.PngImageFile)
assert im.mode == "LA"
im.seek(im.n_frames - 1)
assert im.getpixel((0, 0)) == (128, 191)
assert im.getpixel((64, 32)) == (128, 191)
assert im.getpixel((0, 0)) == (128, 255)
assert im.getpixel((64, 32)) == (128, 255)

with Image.open("Tests/images/apng/mode_palette.png") as im:
assert isinstance(im, PngImagePlugin.PngImageFile)
Expand Down
12 changes: 10 additions & 2 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,12 @@ def load_end(self) -> None:
else:
if self._prev_im and self.blend_op == Blend.OP_OVER:
updated = self._crop(self.im, self.dispose_extent)
if self.im.mode == "RGB" and "transparency" in self.info:
if self.im.mode in {"LA", "RGBA"}:
updated = Image.core.alpha_composite(
self._crop(self._prev_im, self.dispose_extent), updated
)
mask = None
elif self.im.mode == "RGB" and "transparency" in self.info:
mask = updated.convert_transparent(
"RGBA", self.info["transparency"]
)
Expand All @@ -1130,7 +1135,10 @@ def load_end(self) -> None:
self.im = self._prev_im.copy()
else:
self.im = self._prev_im
self.im.paste(updated, self.dispose_extent, mask)
if mask is not None:
self.im.paste(updated, self.dispose_extent, mask)
else:
self.im.paste(updated, self.dispose_extent)

def _getexif(self) -> dict[int, Any] | None:
if "exif" not in self.info:
Expand Down
Loading