Skip to content

Commit b188773

Browse files
committed
Supporting writing TIFF_IFD tag types
1 parent b04d879 commit b188773

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Tests/test_file_libtiff.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,20 @@ def test_subifd(self, tmp_path: Path) -> None:
355355
# Should not segfault
356356
im.save(outfile)
357357

358+
def test_ifd(self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
359+
monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", True)
360+
361+
ifd = TiffImagePlugin.ImageFileDirectory_v2()
362+
ifd[37000] = 100
363+
ifd.tagtype[37000] = TiffTags.IFD
364+
365+
out = tmp_path / "temp.tif"
366+
im = Image.new("L", (1, 1))
367+
im.save(out, tiffinfo=ifd)
368+
369+
with Image.open(out) as reloaded:
370+
assert reloaded.tag_v2[37000] == 100
371+
358372
def test_inknames_tag(
359373
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
360374
) -> None:

src/encode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
974974
status = ImagingLibTiffSetField(
975975
&encoder->state, (ttag_t)key_int, (UINT16)PyLong_AsLong(value)
976976
);
977-
} else if (type == TIFF_LONG) {
977+
} else if (type == TIFF_LONG || type == TIFF_IFD) {
978978
status = ImagingLibTiffSetField(
979979
&encoder->state, (ttag_t)key_int, (UINT32)PyLong_AsLong(value)
980980
);

0 commit comments

Comments
 (0)