Skip to content

Commit

Permalink
Merge pull request #6950 from radarhere/tiff_undefined
Browse files Browse the repository at this point in the history
Resolves #6948
  • Loading branch information
hugovk committed Feb 14, 2023
2 parents 228709e + ad0e9db commit 3986eaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Tests/test_file_tiff_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ def test_writing_other_types_to_bytes(value, tmp_path):
assert reloaded.tag_v2[700] == b"\x01"


def test_writing_other_types_to_undefined(tmp_path):
im = hopper()
info = TiffImagePlugin.ImageFileDirectory_v2()

tag = TiffTags.TAGS_V2[33723]
assert tag.type == TiffTags.UNDEFINED

info[33723] = 1

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

with Image.open(out) as reloaded:
assert reloaded.tag_v2[33723] == b"1"


def test_undefined_zero(tmp_path):
# Check that the tag has not been changed since this test was created
tag = TiffTags.TAGS_V2[45059]
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ def load_undefined(self, data, legacy_api=True):

@_register_writer(7)
def write_undefined(self, value):
if isinstance(value, int):
value = str(value).encode("ascii", "replace")
return value

@_register_loader(10, 8)
Expand Down

0 comments on commit 3986eaf

Please sign in to comment.