Skip to content

Commit

Permalink
Merge pull request #4726 from hugovk/fix-png-disposal-comparison-bug
Browse files Browse the repository at this point in the history
APNG: Fix setting disposal
  • Loading branch information
radarhere authored Jun 29, 2020
2 parents 20282dd + d109d86 commit 4cf7c56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,26 @@ def test_apng_save_disposal(tmp_path):
assert im.getpixel((64, 32)) == (0, 255, 0, 255)


def test_apng_save_disposal_previous(tmp_path):
test_file = str(tmp_path / "temp.png")
size = (128, 64)
transparent = Image.new("RGBA", size, (0, 0, 0, 0))
red = Image.new("RGBA", size, (255, 0, 0, 255))
green = Image.new("RGBA", size, (0, 255, 0, 255))

# test APNG_DISPOSE_OP_NONE
transparent.save(
test_file,
save_all=True,
append_images=[red, green],
disposal=PngImagePlugin.APNG_DISPOSE_OP_PREVIOUS,
)
with Image.open(test_file) as im:
im.seek(2)
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
assert im.getpixel((64, 32)) == (0, 255, 0, 255)


def test_apng_save_blend(tmp_path):
test_file = str(tmp_path / "temp.png")
size = (128, 64)
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ def _write_multiple_frames(im, fp, chunk, rawmode):
prev_disposal = previous["encoderinfo"].get("disposal")
prev_blend = previous["encoderinfo"].get("blend")
if prev_disposal == APNG_DISPOSE_OP_PREVIOUS and len(im_frames) < 2:
prev_disposal == APNG_DISPOSE_OP_BACKGROUND
prev_disposal = APNG_DISPOSE_OP_BACKGROUND

if prev_disposal == APNG_DISPOSE_OP_BACKGROUND:
base_im = previous["im"]
Expand Down

0 comments on commit 4cf7c56

Please sign in to comment.