mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-29 17:33:08 +03:00
initial working version of saving arbitrary tags from the img.tags directory
This commit is contained in:
parent
465ebd3af3
commit
bb9672095b
|
@ -293,6 +293,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
|
|
||||||
def __setitem__(self, tag, value):
|
def __setitem__(self, tag, value):
|
||||||
if not isinstance(value, tuple):
|
if not isinstance(value, tuple):
|
||||||
|
# UNDONE -- this should probably be type, value
|
||||||
value = (value,)
|
value = (value,)
|
||||||
self.tags[tag] = value
|
self.tags[tag] = value
|
||||||
|
|
||||||
|
@ -446,7 +447,10 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
|
|
||||||
if typ == 1:
|
if typ == 1:
|
||||||
# byte data
|
# byte data
|
||||||
data = value
|
if isinstance(value, tuple):
|
||||||
|
data = value = value[-1]
|
||||||
|
else:
|
||||||
|
data = value
|
||||||
elif typ == 7:
|
elif typ == 7:
|
||||||
# untyped data
|
# untyped data
|
||||||
data = value = b"".join(value)
|
data = value = b"".join(value)
|
||||||
|
@ -493,6 +497,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
count = len(value)
|
count = len(value)
|
||||||
if typ == 5:
|
if typ == 5:
|
||||||
count = count // 2 # adjust for rational data field
|
count = count // 2 # adjust for rational data field
|
||||||
|
|
||||||
append((tag, typ, count, o32(offset), data))
|
append((tag, typ, count, o32(offset), data))
|
||||||
offset = offset + len(data)
|
offset = offset + len(data)
|
||||||
if offset & 1:
|
if offset & 1:
|
||||||
|
@ -931,6 +936,13 @@ def _save(im, fp, filename):
|
||||||
for key in (RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION):
|
for key in (RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION):
|
||||||
if key in im.tag.tagdata:
|
if key in im.tag.tagdata:
|
||||||
ifd[key] = im.tag.tagdata.get(key)
|
ifd[key] = im.tag.tagdata.get(key)
|
||||||
|
|
||||||
|
info = im.encoderinfo.get("tiffinfo",[])
|
||||||
|
print("info %s "% info)
|
||||||
|
for key in info:
|
||||||
|
if key in im.tag:
|
||||||
|
ifd[key] = im.tag.get(key)
|
||||||
|
print ("added %s" %key)
|
||||||
# preserve some more tags from original TIFF image file
|
# preserve some more tags from original TIFF image file
|
||||||
# -- 2008-06-06 Florian Hoech
|
# -- 2008-06-06 Florian Hoech
|
||||||
ifd.tagtype = im.tag.tagtype
|
ifd.tagtype = im.tag.tagtype
|
||||||
|
@ -941,6 +953,7 @@ def _save(im, fp, filename):
|
||||||
# which support profiles as TIFF) -- 2008-06-06 Florian Hoech
|
# which support profiles as TIFF) -- 2008-06-06 Florian Hoech
|
||||||
if "icc_profile" in im.info:
|
if "icc_profile" in im.info:
|
||||||
ifd[ICCPROFILE] = im.info["icc_profile"]
|
ifd[ICCPROFILE] = im.info["icc_profile"]
|
||||||
|
|
||||||
if "description" in im.encoderinfo:
|
if "description" in im.encoderinfo:
|
||||||
ifd[IMAGEDESCRIPTION] = im.encoderinfo["description"]
|
ifd[IMAGEDESCRIPTION] = im.encoderinfo["description"]
|
||||||
if "resolution" in im.encoderinfo:
|
if "resolution" in im.encoderinfo:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user