mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Merge pull request #3588 from radarhere/mpo_frame_size
Change size of MPO image to match frame
This commit is contained in:
commit
3b92de5ddc
BIN
Tests/images/sugarshack_frame_size.mpo
Normal file
BIN
Tests/images/sugarshack_frame_size.mpo
Normal file
Binary file not shown.
After Width: | Height: | Size: 117 KiB |
|
@ -55,6 +55,15 @@ class TestFileMpo(PillowTestCase):
|
|||
self.assertEqual(info[296], 2)
|
||||
self.assertEqual(info[34665], 188)
|
||||
|
||||
def test_frame_size(self):
|
||||
# This image has been hexedited to contain a different size
|
||||
# in the EXIF data of the second frame
|
||||
im = Image.open("Tests/images/sugarshack_frame_size.mpo")
|
||||
self.assertEqual(im.size, (640, 480))
|
||||
|
||||
im.seek(1)
|
||||
self.assertEqual(im.size, (680, 480))
|
||||
|
||||
def test_mp(self):
|
||||
for test_file in test_files:
|
||||
im = Image.open(test_file)
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
# See the README file for information on usage and redistribution.
|
||||
#
|
||||
|
||||
from . import Image, JpegImagePlugin
|
||||
from . import Image, ImageFile, JpegImagePlugin
|
||||
from ._binary import i16be as i16
|
||||
|
||||
# __version__ is deprecated and will be removed in a future version. Use
|
||||
# PIL.__version__ instead.
|
||||
|
@ -78,6 +79,20 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
|
|||
return
|
||||
self.fp = self.__fp
|
||||
self.offset = self.__mpoffsets[frame]
|
||||
|
||||
self.fp.seek(self.offset + 2) # skip SOI marker
|
||||
if "parsed_exif" in self.info:
|
||||
del self.info["parsed_exif"]
|
||||
if i16(self.fp.read(2)) == 0xFFE1: # APP1
|
||||
n = i16(self.fp.read(2))-2
|
||||
self.info["exif"] = ImageFile._safe_read(self.fp, n)
|
||||
|
||||
exif = self._getexif()
|
||||
if 40962 in exif and 40963 in exif:
|
||||
self._size = (exif[40962], exif[40963])
|
||||
elif "exif" in self.info:
|
||||
del self.info["exif"]
|
||||
|
||||
self.tile = [
|
||||
("jpeg", (0, 0) + self.size, self.offset, (self.mode, ""))
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user