Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update GIF frame position until local image is found #6219

Merged
merged 1 commit into from May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Tests/images/comment_after_last_frame.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 17 additions & 10 deletions Tests/test_file_gif.py
Expand Up @@ -341,16 +341,23 @@ def test_seek_rewind():
assert_image_equal(im, expected)


def test_n_frames():
for path, n_frames in [[TEST_GIF, 1], ["Tests/images/iss634.gif", 42]]:
# Test is_animated before n_frames
with Image.open(path) as im:
assert im.is_animated == (n_frames != 1)

# Test is_animated after n_frames
with Image.open(path) as im:
assert im.n_frames == n_frames
assert im.is_animated == (n_frames != 1)
@pytest.mark.parametrize(
"path, n_frames",
(
(TEST_GIF, 1),
("Tests/images/comment_after_last_frame.gif", 2),
("Tests/images/iss634.gif", 42),
),
)
def test_n_frames(path, n_frames):
# Test is_animated before n_frames
with Image.open(path) as im:
assert im.is_animated == (n_frames != 1)

# Test is_animated after n_frames
with Image.open(path) as im:
assert im.n_frames == n_frames
assert im.is_animated == (n_frames != 1)


def test_no_change():
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/GifImagePlugin.py
Expand Up @@ -183,8 +183,6 @@ def _seek(self, frame, update_image=True):
if not s or s == b";":
raise EOFError

self.__frame = frame

self.tile = []

palette = None
Expand Down Expand Up @@ -283,6 +281,8 @@ def _seek(self, frame, update_image=True):
if interlace is None:
# self.__fp = None
raise EOFError

self.__frame = frame
if not update_image:
return

Expand Down