Skip to content

Commit

Permalink
Merge pull request #6779 from radarhere/gif_duration
Browse files Browse the repository at this point in the history
Resolves #6778
  • Loading branch information
hugovk committed Dec 13, 2022
2 parents 0d6440d + 72ac7d1 commit d013fbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Binary file added Tests/images/duplicate_frame.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions Tests/test_file_gif.py
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/GifImagePlugin.py
Expand Up @@ -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:
Expand Down

0 comments on commit d013fbf

Please sign in to comment.