From ddd4f007209a3af7f8976322c13c97f205cc4f06 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 23 Oct 2025 20:03:14 +1100 Subject: [PATCH] Support writing IFD tag types --- Tests/test_file_libtiff.py | 14 ++++++++++++++ src/encode.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index e53832db3..38e4111a1 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -355,6 +355,20 @@ class TestFileLibTiff(LibTiffTestCase): # Should not segfault im.save(outfile) + def test_ifd(self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: + monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", True) + + ifd = TiffImagePlugin.ImageFileDirectory_v2() + ifd[37000] = 100 + ifd.tagtype[37000] = TiffTags.IFD + + out = tmp_path / "temp.tif" + im = Image.new("L", (1, 1)) + im.save(out, tiffinfo=ifd) + + with Image.open(out) as reloaded: + assert reloaded.tag_v2[37000] == 100 + def test_inknames_tag( self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path ) -> None: diff --git a/src/encode.c b/src/encode.c index f0e204bc6..2e9ef843d 100644 --- a/src/encode.c +++ b/src/encode.c @@ -974,7 +974,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) { status = ImagingLibTiffSetField( &encoder->state, (ttag_t)key_int, (UINT16)PyLong_AsLong(value) ); - } else if (type == TIFF_LONG) { + } else if (type == TIFF_LONG || type == TIFF_IFD) { status = ImagingLibTiffSetField( &encoder->state, (ttag_t)key_int, (UINT32)PyLong_AsLong(value) );