mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 09:14:27 +03:00
Merge pull request #6817 from radarhere/mpo_exif
This commit is contained in:
commit
e0eca1f3d9
|
@ -80,7 +80,10 @@ def test_app(test_file):
|
||||||
|
|
||||||
@pytest.mark.parametrize("test_file", test_files)
|
@pytest.mark.parametrize("test_file", test_files)
|
||||||
def test_exif(test_file):
|
def test_exif(test_file):
|
||||||
with Image.open(test_file) as im:
|
with Image.open(test_file) as im_original:
|
||||||
|
im_reloaded = roundtrip(im_original, save_all=True, exif=im_original.getexif())
|
||||||
|
|
||||||
|
for im in (im_original, im_reloaded):
|
||||||
info = im._getexif()
|
info = im._getexif()
|
||||||
assert info[272] == "Nintendo 3DS"
|
assert info[272] == "Nintendo 3DS"
|
||||||
assert info[296] == 2
|
assert info[296] == 2
|
||||||
|
|
|
@ -52,14 +52,22 @@ def _save_all(im, fp, filename):
|
||||||
_save(im, fp, filename)
|
_save(im, fp, filename)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mpf_offset = 28
|
||||||
offsets = []
|
offsets = []
|
||||||
for imSequence in itertools.chain([im], append_images):
|
for imSequence in itertools.chain([im], append_images):
|
||||||
for im_frame in ImageSequence.Iterator(imSequence):
|
for im_frame in ImageSequence.Iterator(imSequence):
|
||||||
if not offsets:
|
if not offsets:
|
||||||
# APP2 marker
|
# APP2 marker
|
||||||
im.encoderinfo["extra"] = (
|
im_frame.encoderinfo["extra"] = (
|
||||||
b"\xFF\xE2" + struct.pack(">H", 6 + 82) + b"MPF\0" + b" " * 82
|
b"\xFF\xE2" + struct.pack(">H", 6 + 82) + b"MPF\0" + b" " * 82
|
||||||
)
|
)
|
||||||
|
exif = im_frame.encoderinfo.get("exif")
|
||||||
|
if isinstance(exif, Image.Exif):
|
||||||
|
exif = exif.tobytes()
|
||||||
|
im_frame.encoderinfo["exif"] = exif
|
||||||
|
if exif:
|
||||||
|
mpf_offset += 4 + len(exif)
|
||||||
|
|
||||||
JpegImagePlugin._save(im_frame, fp, filename)
|
JpegImagePlugin._save(im_frame, fp, filename)
|
||||||
offsets.append(fp.tell())
|
offsets.append(fp.tell())
|
||||||
else:
|
else:
|
||||||
|
@ -79,11 +87,11 @@ def _save_all(im, fp, filename):
|
||||||
mptype = 0x000000 # Undefined
|
mptype = 0x000000 # Undefined
|
||||||
mpentries += struct.pack("<LLLHH", mptype, size, data_offset, 0, 0)
|
mpentries += struct.pack("<LLLHH", mptype, size, data_offset, 0, 0)
|
||||||
if i == 0:
|
if i == 0:
|
||||||
data_offset -= 28
|
data_offset -= mpf_offset
|
||||||
data_offset += size
|
data_offset += size
|
||||||
ifd[0xB002] = mpentries
|
ifd[0xB002] = mpentries
|
||||||
|
|
||||||
fp.seek(28)
|
fp.seek(mpf_offset)
|
||||||
fp.write(b"II\x2A\x00" + o32le(8) + ifd.tobytes(8))
|
fp.write(b"II\x2A\x00" + o32le(8) + ifd.tobytes(8))
|
||||||
fp.seek(0, os.SEEK_END)
|
fp.seek(0, os.SEEK_END)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user