mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Fixed writing int as ASCII tag
This commit is contained in:
parent
0d6440d9f2
commit
6da4169f37
|
@ -185,20 +185,21 @@ def test_iptc(tmp_path):
|
||||||
im.save(out)
|
im.save(out)
|
||||||
|
|
||||||
|
|
||||||
def test_writing_bytes_to_ascii(tmp_path):
|
def test_writing_other_types_to_ascii(tmp_path):
|
||||||
im = hopper()
|
im = hopper()
|
||||||
info = TiffImagePlugin.ImageFileDirectory_v2()
|
info = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
|
|
||||||
tag = TiffTags.TAGS_V2[271]
|
tag = TiffTags.TAGS_V2[271]
|
||||||
assert tag.type == TiffTags.ASCII
|
assert tag.type == TiffTags.ASCII
|
||||||
|
|
||||||
info[271] = b"test"
|
|
||||||
|
|
||||||
out = str(tmp_path / "temp.tiff")
|
out = str(tmp_path / "temp.tiff")
|
||||||
im.save(out, tiffinfo=info)
|
for (value, expected) in {b"test": "test", 1: "1"}.items():
|
||||||
|
info[271] = value
|
||||||
|
|
||||||
with Image.open(out) as reloaded:
|
im.save(out, tiffinfo=info)
|
||||||
assert reloaded.tag_v2[271] == "test"
|
|
||||||
|
with Image.open(out) as reloaded:
|
||||||
|
assert reloaded.tag_v2[271] == expected
|
||||||
|
|
||||||
|
|
||||||
def test_writing_int_to_bytes(tmp_path):
|
def test_writing_int_to_bytes(tmp_path):
|
||||||
|
|
|
@ -732,6 +732,8 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
@_register_writer(2)
|
@_register_writer(2)
|
||||||
def write_string(self, value):
|
def write_string(self, value):
|
||||||
# remerge of https://github.com/python-pillow/Pillow/pull/1416
|
# remerge of https://github.com/python-pillow/Pillow/pull/1416
|
||||||
|
if isinstance(value, int):
|
||||||
|
value = str(value)
|
||||||
if not isinstance(value, bytes):
|
if not isinstance(value, bytes):
|
||||||
value = value.encode("ascii", "replace")
|
value = value.encode("ascii", "replace")
|
||||||
return value + b"\0"
|
return value + b"\0"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user