Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ 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")
@skip_unless_feature("zlib")
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Plugin reference
----------------------------

.. automodule:: PIL.PngImagePlugin
:members: ChunkStream, PngImageFile, PngStream, getchunks, is_cid, putchunk
:members: ChunkStream, PngStream, getchunks, is_cid, putchunk
:show-inheritance:
.. autoclass:: PIL.PngImagePlugin.ChunkStream
:members:
Expand Down
17 changes: 4 additions & 13 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def _open(self):
self._text = None
self.tile = self.png.im_tile
self.custom_mimetype = self.png.im_custom_mimetype
self._n_frames = self.png.im_n_frames
self.n_frames = self.png.im_n_frames or 1
self.default_image = self.info.get("default_image", False)

if self.png.im_palette:
Expand All @@ -685,15 +685,16 @@ def _open(self):
else:
self.__prepare_idat = length # used by load_prepare()

if self._n_frames is not None:
if self.png.im_n_frames is not None:
self._close_exclusive_fp_after_loading = False
self.png.save_rewind()
self.__rewind_idat = self.__prepare_idat
self.__rewind = self.__fp.tell()
if self.default_image:
# IDAT chunk contains default image and not first animation frame
self._n_frames += 1
self.n_frames += 1
self._seek(0)
self.is_animated = self.n_frames > 1

@property
def text(self):
Expand All @@ -710,16 +711,6 @@ def text(self):
self.seek(frame)
return self._text

@property
def n_frames(self):
if self._n_frames is None:
return 1
return self._n_frames

@property
def is_animated(self):
return self._n_frames is not None and self._n_frames > 1

def verify(self):
"""Verify PNG file"""

Expand Down