Corrected duration when combining multiple GIF frames into single frame #7521
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here is one of our tests, originally added in #4003
Pillow/Tests/test_file_gif.py
Lines 858 to 875 in 1c2f2c7
Saving multiple identical GIF frames results in a single frame. That PR changed GifImagePlugin to also give that single frame the combined duration. However, if you look at the test, it is saving three frames, but adding together a sequence of four durations. This PR ignores the fourth duration, so that a merged GIF is not longer than it would have been if the frames were not identical.
A second effect of this change is that when saving multiple identical GIF frames with an integer duration (see the last parameter in the test), rather than a sequence, the duration is multiplied by the number of frames, rather than just being the original integer. This again means that a merged GIF has the same total duration that it would have had if the frames were not identical.