Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def test_sanity(self, tmp_path):
assert im.size == (128, 128)
assert im.format == "PNG"
assert im.get_format_mimetype() == "image/png"
assert im.n_frames == 1
assert not im.is_animated

for mode in ["1", "L", "P", "RGB", "I", "I;16"]:
im = hopper(mode)
Expand Down Expand Up @@ -636,6 +638,8 @@ def test_tell(self):
def test_seek(self):
with Image.open(TEST_PNG_FILE) as im:
im.seek(0)
with pytest.raises(EOFError):
im.seek(1)


@pytest.mark.skipif(is_win32(), reason="Requires Unix or macOS")
Expand Down
8 changes: 6 additions & 2 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ def _open(self):
if self.fp.read(8) != _MAGIC:
raise SyntaxError("not a PNG file")
self.__fp = self.fp
self.__frame = 0

#
# Parse headers up to the first IDAT or fDAT chunk
Expand Down Expand Up @@ -685,7 +684,12 @@ def _open(self):
else:
self.__prepare_idat = length # used by load_prepare()

if self._n_frames is not None:
if self._n_frames is None:
# standard PNG image, frame-related attributes still need to be
# initialized for seek()/_seek_check() to behave as expected
self.__frame = 0
self._n_frames = 1
else:
self._close_exclusive_fp_after_loading = False
self.png.save_rewind()
self.__rewind_idat = self.__prepare_idat
Expand Down