From 45aec957172e111ee6e721e0edd00a58e92448e3 Mon Sep 17 00:00:00 2001 From: thak1411 Date: Tue, 13 Jul 2021 12:07:36 +0900 Subject: [PATCH 1/3] Fixed round error in saving apng file --- src/PIL/PngImagePlugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index bd886e218..cd679d2c3 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -1117,12 +1117,12 @@ def _write_multiple_frames(im, fp, chunk, rawmode): and prev_disposal == encoderinfo.get("disposal") and prev_blend == encoderinfo.get("blend") ): - duration = encoderinfo.get("duration", 0) - if duration: + now_duration = encoderinfo.get("duration", 0) + if now_duration: if "duration" in previous["encoderinfo"]: - previous["encoderinfo"]["duration"] += duration + previous["encoderinfo"]["duration"] += now_duration else: - previous["encoderinfo"]["duration"] = duration + previous["encoderinfo"]["duration"] = now_duration continue else: bbox = None From 0521ac71e096eeca0c37ce772a5a3275c023b1fd Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 13 Jul 2021 18:43:56 +1000 Subject: [PATCH 2/3] Renamed variable --- src/PIL/PngImagePlugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index cd679d2c3..a91393726 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -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 From ca16cf2aacd5a84c7819dcdbba3cc6a46649b83d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 13 Jul 2021 18:47:55 +1000 Subject: [PATCH 3/3] Added test --- Tests/test_file_apng.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index 7fb6f59d4..15e007ca1 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -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