diff --git a/Tests/images/duplicate_frame.gif b/Tests/images/duplicate_frame.gif new file mode 100644 index 00000000000..ef0c894a540 Binary files /dev/null and b/Tests/images/duplicate_frame.gif differ diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 926f5c1eea8..49820d6daea 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -791,6 +791,22 @@ def test_roundtrip_info_duration(tmp_path): ] == duration_list +def test_roundtrip_info_duration_combined(tmp_path): + out = str(tmp_path / "temp.gif") + with Image.open("Tests/images/duplicate_frame.gif") as im: + assert [frame.info["duration"] for frame in ImageSequence.Iterator(im)] == [ + 1000, + 1000, + 1000, + ] + im.save(out, save_all=True) + + with Image.open(out) as reloaded: + assert [ + frame.info["duration"] for frame in ImageSequence.Iterator(reloaded) + ] == [1000, 2000] + + def test_identical_frames(tmp_path): duration_list = [1000, 1500, 2000, 4000] diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index dd1b21f2e63..13894c8d6d9 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -618,7 +618,7 @@ def _write_multiple_frames(im, fp, palette): bbox = delta.getbbox() if not bbox: # This frame is identical to the previous frame - if duration: + if encoderinfo.get("duration"): previous["encoderinfo"]["duration"] += encoderinfo["duration"] continue else: