Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/round-error
Browse files Browse the repository at this point in the history
Added test
  • Loading branch information
thak1411 committed Jul 13, 2021
2 parents 45aec95 + ca16cf2 commit ca0738d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Tests/test_file_apng.py
Expand Up @@ -433,7 +433,9 @@ def test_apng_save_duration_loop(tmp_path):

# test removal of duplicated frames
frame = Image.new("RGBA", (128, 64), (255, 0, 0, 255))
frame.save(test_file, save_all=True, append_images=[frame], duration=[500, 250])
frame.save(
test_file, save_all=True, append_images=[frame, frame], duration=[500, 100, 150]
)
with Image.open(test_file) as im:
im.load()
assert im.n_frames == 1
Expand Down
8 changes: 4 additions & 4 deletions src/PIL/PngImagePlugin.py
Expand Up @@ -1117,12 +1117,12 @@ def _write_multiple_frames(im, fp, chunk, rawmode):
and prev_disposal == encoderinfo.get("disposal")
and prev_blend == encoderinfo.get("blend")
):
now_duration = encoderinfo.get("duration", 0)
if now_duration:
frame_duration = encoderinfo.get("duration", 0)
if frame_duration:
if "duration" in previous["encoderinfo"]:
previous["encoderinfo"]["duration"] += now_duration
previous["encoderinfo"]["duration"] += frame_duration
else:
previous["encoderinfo"]["duration"] = now_duration
previous["encoderinfo"]["duration"] = frame_duration
continue
else:
bbox = None
Expand Down

0 comments on commit ca0738d

Please sign in to comment.