Skip to content

Commit

Permalink
Merge pull request #6890 from radarhere/tiff_byte
Browse files Browse the repository at this point in the history
Allow writing IFDRational to BYTE tag
  • Loading branch information
hugovk committed Jan 14, 2023
2 parents 145b80b + e48aead commit eae294c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Tests/test_file_tiff_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ def test_writing_other_types_to_ascii(value, expected, tmp_path):
assert reloaded.tag_v2[271] == expected


def test_writing_int_to_bytes(tmp_path):
@pytest.mark.parametrize("value", (1, IFDRational(1)))
def test_writing_other_types_to_bytes(value, tmp_path):
im = hopper()
info = TiffImagePlugin.ImageFileDirectory_v2()

tag = TiffTags.TAGS_V2[700]
assert tag.type == TiffTags.BYTE

info[700] = 1
info[700] = value

out = str(tmp_path / "temp.tiff")
im.save(out, tiffinfo=info)
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ def load_byte(self, data, legacy_api=True):

@_register_writer(1) # Basic type, except for the legacy API.
def write_byte(self, data):
if isinstance(data, IFDRational):
data = int(data)
if isinstance(data, int):
data = bytes((data,))
return data
Expand Down

0 comments on commit eae294c

Please sign in to comment.