mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Allow writing IFDRational to UNDEFINED tag
This commit is contained in:
parent
18af646365
commit
904b8e549c
|
@ -224,14 +224,17 @@ def test_writing_other_types_to_bytes(value: int | IFDRational, tmp_path: Path)
|
||||||
assert reloaded.tag_v2[700] == b"\x01"
|
assert reloaded.tag_v2[700] == b"\x01"
|
||||||
|
|
||||||
|
|
||||||
def test_writing_other_types_to_undefined(tmp_path: Path) -> None:
|
@pytest.mark.parametrize("value", (1, IFDRational(1)))
|
||||||
|
def test_writing_other_types_to_undefined(
|
||||||
|
value: int | IFDRational, tmp_path: Path
|
||||||
|
) -> None:
|
||||||
im = hopper()
|
im = hopper()
|
||||||
info = TiffImagePlugin.ImageFileDirectory_v2()
|
info = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
|
|
||||||
tag = TiffTags.TAGS_V2[33723]
|
tag = TiffTags.TAGS_V2[33723]
|
||||||
assert tag.type == TiffTags.UNDEFINED
|
assert tag.type == TiffTags.UNDEFINED
|
||||||
|
|
||||||
info[33723] = 1
|
info[33723] = value
|
||||||
|
|
||||||
out = str(tmp_path / "temp.tiff")
|
out = str(tmp_path / "temp.tiff")
|
||||||
im.save(out, tiffinfo=info)
|
im.save(out, tiffinfo=info)
|
||||||
|
|
|
@ -790,6 +790,8 @@ class ImageFileDirectory_v2(_IFDv2Base):
|
||||||
|
|
||||||
@_register_writer(7)
|
@_register_writer(7)
|
||||||
def write_undefined(self, value):
|
def write_undefined(self, value):
|
||||||
|
if isinstance(value, IFDRational):
|
||||||
|
value = int(value)
|
||||||
if isinstance(value, int):
|
if isinstance(value, int):
|
||||||
value = str(value).encode("ascii", "replace")
|
value = str(value).encode("ascii", "replace")
|
||||||
return value
|
return value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user