Skip to content

Commit

Permalink
Merge 1564a24 into d96f657
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangying000 committed Aug 23, 2019
2 parents d96f657 + 1564a24 commit c02526d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,28 @@ def test_identical_frames(self):
# Assert that the new duration is the total of the identical frames
self.assertEqual(reread.info["duration"], 4500)

def test_identical_frames_to_single_frame(self):
duration_list = [1000, 1500, 2000, 4000]

out = self.tempfile("temp.gif")
im_list = [
Image.new("L", (100, 100), "#000"),
Image.new("L", (100, 100), "#000"),
Image.new("L", (100, 100), "#000"),
]

# duration as list
im_list[0].save(
out, save_all=True, append_images=im_list[1:], duration=duration_list
)
reread = Image.open(out)

# Assert that all frames were combined
self.assertEqual(reread.n_frames, 1)

# Assert that the new duration is the total of the identical frames
self.assertEqual(reread.info["duration"], 8500)

def test_number_of_loops(self):
number_of_loops = 2

Expand Down
3 changes: 3 additions & 0 deletions src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ def _write_multiple_frames(im, fp, palette):
offset = frame_data["bbox"][:2]
_write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"])
return True
elif "duration" in im.encoderinfo:
# Since multiple frames will not be written, add together the frame durations
im.encoderinfo["duration"] = sum(im.encoderinfo["duration"])


def _save_all(im, fp, filename):
Expand Down

0 comments on commit c02526d

Please sign in to comment.