Skip to content

Commit 849c881

Browse files
committed
Support writing SIGNED_RATIONAL tag types
1 parent ddd4f00 commit 849c881

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Tests/test_file_libtiff.py

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

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

src/encode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
10021002
status = ImagingLibTiffSetField(
10031003
&encoder->state, (ttag_t)key_int, PyBytes_AsString(value)
10041004
);
1005-
} else if (type == TIFF_RATIONAL) {
1005+
} else if (type == TIFF_SRATIONAL || type == TIFF_RATIONAL) {
10061006
status = ImagingLibTiffSetField(
10071007
&encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value)
10081008
);

0 commit comments

Comments
 (0)