mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Trim id_section if it is greater than 255 characters
This commit is contained in:
parent
9e4c54e10f
commit
325ca3cede
|
@ -124,6 +124,13 @@ class TestFileTga(PillowTestCase):
|
|||
test_im = Image.open(out)
|
||||
self.assertEqual(test_im.info["id_section"], b"Test content")
|
||||
|
||||
# Save with custom id section greater than 255 characters
|
||||
id_section = b"Test content" * 25
|
||||
self.assert_warning(UserWarning,
|
||||
lambda: im.save(out, id_section=id_section))
|
||||
test_im = Image.open(out)
|
||||
self.assertEqual(test_im.info["id_section"], id_section[:255])
|
||||
|
||||
test_file = "Tests/images/tga_id_field.tga"
|
||||
im = Image.open(test_file)
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
from . import Image, ImageFile, ImagePalette
|
||||
from ._binary import i8, i16le as i16, o8, o16le as o16
|
||||
|
||||
import warnings
|
||||
|
||||
__version__ = "0.3"
|
||||
|
||||
|
||||
|
@ -163,6 +165,10 @@ def _save(im, fp, filename):
|
|||
id_section = im.encoderinfo.get("id_section",
|
||||
im.info.get("id_section", ""))
|
||||
idlen = len(id_section)
|
||||
if idlen > 255:
|
||||
idlen = 255
|
||||
id_section = id_section[:255]
|
||||
warnings.warn("id_section has been trimmed to 255 characters")
|
||||
|
||||
if colormaptype:
|
||||
colormapfirst, colormaplength, colormapentry = 0, 256, 24
|
||||
|
|
Loading…
Reference in New Issue
Block a user