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

Reset size when seeking away from "Large Thumbnail" MPO frame #6101

Merged
merged 1 commit into from Mar 2, 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
3 changes: 3 additions & 0 deletions Tests/test_file_mpo.py
Expand Up @@ -85,6 +85,9 @@ def test_frame_size():
im.seek(1)
assert im.size == (680, 480)

im.seek(0)
assert im.size == (640, 480)


def test_ignore_frame_size():
# Ignore the different size of the second frame
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/MpoImagePlugin.py
Expand Up @@ -46,6 +46,7 @@ def _open(self):
self._after_jpeg_open()

def _after_jpeg_open(self, mpheader=None):
self._initial_size = self.size
self.mpinfo = mpheader if mpheader is not None else self._getmp()
self.n_frames = self.mpinfo[0xB001]
self.__mpoffsets = [
Expand Down Expand Up @@ -77,6 +78,7 @@ def seek(self, frame):
segment = self.fp.read(2)
if not segment:
raise ValueError("No data found for frame")
self._size = self._initial_size
if i16(segment) == 0xFFE1: # APP1
n = i16(self.fp.read(2)) - 2
self.info["exif"] = ImageFile._safe_read(self.fp, n)
Expand Down