Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed writing int as BYTE tag #6740

Merged
merged 1 commit into from Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions Tests/test_file_tiff_metadata.py
Expand Up @@ -201,6 +201,22 @@ def test_writing_bytes_to_ascii(tmp_path):
assert reloaded.tag_v2[271] == "test"


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

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

info[700] = 1

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

with Image.open(out) as reloaded:
assert reloaded.tag_v2[700] == b"\x01"


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
Expand Up @@ -719,6 +719,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, int):
data = bytes((data,))
return data

@_register_loader(2, 1)
Expand Down