forked from python-pillow/Pillow
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only preserve IPTC_NAA_CHUNK tag if type if BYTE or UNDEFINED
- Loading branch information
Showing
2 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1653,6 +1653,16 @@ def _save(im, fp, filename): | |
except Exception: | ||
pass # might not be an IFD. Might not have populated type | ||
|
||
legacy_ifd = {} | ||
if hasattr(im, "tag"): | ||
legacy_ifd = im.tag.to_v2() | ||
|
||
supplied_tags = {**legacy_ifd, **getattr(im, "tag_v2", {})} | ||
if SAMPLEFORMAT in supplied_tags: | ||
# SAMPLEFORMAT is determined by the image format and should not be copied | ||
# from legacy_ifd. | ||
del supplied_tags[SAMPLEFORMAT] | ||
|
||
# additions written by Greg Couch, [email protected] | ||
# inspired by image-sig posting from Kevin Cazabon, [email protected] | ||
if hasattr(im, "tag_v2"): | ||
|
@@ -1666,8 +1676,14 @@ def _save(im, fp, filename): | |
XMP, | ||
): | ||
if key in im.tag_v2: | ||
ifd[key] = im.tag_v2[key] | ||
ifd.tagtype[key] = im.tag_v2.tagtype[key] | ||
if key == IPTC_NAA_CHUNK and im.tag_v2.tagtype[key] not in ( | ||
TiffTags.BYTE, | ||
TiffTags.UNDEFINED, | ||
): | ||
del supplied_tags[key] | ||
else: | ||
ifd[key] = im.tag_v2[key] | ||
ifd.tagtype[key] = im.tag_v2.tagtype[key] | ||
|
||
# preserve ICC profile (should also work when saving other formats | ||
# which support profiles as TIFF) -- 2008-06-06 Florian Hoech | ||
|
@@ -1807,16 +1823,6 @@ def _save(im, fp, filename): | |
# Merge the ones that we have with (optional) more bits from | ||
# the original file, e.g x,y resolution so that we can | ||
# save(load('')) == original file. | ||
legacy_ifd = {} | ||
if hasattr(im, "tag"): | ||
legacy_ifd = im.tag.to_v2() | ||
|
||
# SAMPLEFORMAT is determined by the image format and should not be copied | ||
# from legacy_ifd. | ||
supplied_tags = {**getattr(im, "tag_v2", {}), **legacy_ifd} | ||
if SAMPLEFORMAT in supplied_tags: | ||
del supplied_tags[SAMPLEFORMAT] | ||
|
||
for tag, value in itertools.chain(ifd.items(), supplied_tags.items()): | ||
# Libtiff can only process certain core items without adding | ||
# them to the custom dictionary. | ||
|