Skip to content

Commit 4e92ee0

Browse files
authored
Merge pull request #7840 from radarhere/write_undefined
2 parents 9fec5d5 + 9637ea7 commit 4e92ee0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Tests/test_file_tiff_metadata.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,17 @@ def test_writing_other_types_to_bytes(value: int | IFDRational, tmp_path: Path)
224224
assert reloaded.tag_v2[700] == b"\x01"
225225

226226

227-
def test_writing_other_types_to_undefined(tmp_path: Path) -> None:
227+
@pytest.mark.parametrize("value", (1, IFDRational(1)))
228+
def test_writing_other_types_to_undefined(
229+
value: int | IFDRational, tmp_path: Path
230+
) -> None:
228231
im = hopper()
229232
info = TiffImagePlugin.ImageFileDirectory_v2()
230233

231234
tag = TiffTags.TAGS_V2[33723]
232235
assert tag.type == TiffTags.UNDEFINED
233236

234-
info[33723] = 1
237+
info[33723] = value
235238

236239
out = str(tmp_path / "temp.tiff")
237240
im.save(out, tiffinfo=info)

src/PIL/TiffImagePlugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ def load_undefined(self, data, legacy_api=True):
790790

791791
@_register_writer(7)
792792
def write_undefined(self, value):
793+
if isinstance(value, IFDRational):
794+
value = int(value)
793795
if isinstance(value, int):
794796
value = str(value).encode("ascii", "replace")
795797
return value

0 commit comments

Comments
 (0)