Skip to content

Commit 962530b

Browse files
committed
Support saving variable length rational TIFF tags by default
1 parent 9fd4af5 commit 962530b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Tests/test_file_libtiff.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ def test_whitepoint_tag(
367367
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
368368
assert reloaded.tag_v2[318] == pytest.approx((0.3127, 0.3289))
369369

370+
# Save tag by default
371+
with Image.open("Tests/images/rdf.tif") as im:
372+
out = tmp_path / "temp2.tif"
373+
im.save(out)
374+
375+
with Image.open(out) as reloaded:
376+
assert reloaded.tag_v2[318] == pytest.approx((0.3127, 0.3289999))
377+
370378
def test_xmlpacket_tag(
371379
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
372380
) -> None:

src/PIL/TiffImagePlugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,10 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
19361936
types[tag] = TiffTags.LONG8
19371937
elif tag in ifd.tagtype:
19381938
types[tag] = ifd.tagtype[tag]
1939-
elif not (isinstance(value, (int, float, str, bytes))):
1940-
continue
1941-
else:
1939+
elif isinstance(value, (int, float, str, bytes)) or (
1940+
isinstance(value, tuple)
1941+
and all(isinstance(v, (int, float, IFDRational)) for v in value)
1942+
):
19421943
type = TiffTags.lookup(tag).type
19431944
if type:
19441945
types[tag] = type

0 commit comments

Comments
 (0)