mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Corrected version number when saving GIFs
This commit is contained in:
parent
f64bc891d4
commit
b8ff91ab3b
|
@ -537,8 +537,19 @@ def getheader(im, palette=None, info=None):
|
|||
|
||||
# Header Block
|
||||
# http://www.matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp
|
||||
|
||||
version = b"87a"
|
||||
for extensionKey in ["transparency", "duration", "loop"]:
|
||||
if info and extensionKey in info and \
|
||||
not (extensionKey == "duration" and info[extensionKey] == 0):
|
||||
version = b"89a"
|
||||
break
|
||||
else:
|
||||
if im.info.get("version") == "89a":
|
||||
version = b"89a"
|
||||
|
||||
header = [
|
||||
b"GIF87a" + # signature + version
|
||||
b"GIF"+version + # signature + version
|
||||
o16(im.size[0]) + # canvas width
|
||||
o16(im.size[1]) # canvas height
|
||||
]
|
||||
|
|
|
@ -24,6 +24,7 @@ class TestFileGif(PillowTestCase):
|
|||
self.assertEqual(im.mode, "P")
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
self.assertEqual(im.format, "GIF")
|
||||
self.assertEqual(im.info["version"], b"GIF89a")
|
||||
|
||||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
@ -266,6 +267,34 @@ class TestFileGif(PillowTestCase):
|
|||
|
||||
self.assertEqual(reread.info['background'], im.info['background'])
|
||||
|
||||
def test_version(self):
|
||||
out = self.tempfile('temp.gif')
|
||||
|
||||
# Test that GIF87a is used by default
|
||||
im = Image.new('L', (100, 100), '#000')
|
||||
im.save(out)
|
||||
reread = Image.open(out)
|
||||
self.assertEqual(reread.info["version"], b"GIF87a")
|
||||
|
||||
# Test that adding a GIF89a feature changes the version
|
||||
im.info["transparency"] = 1
|
||||
im.save(out)
|
||||
reread = Image.open(out)
|
||||
self.assertEqual(reread.info["version"], b"GIF89a")
|
||||
|
||||
# Test that a GIF87a image is also saved in that format
|
||||
im = Image.open(TEST_GIF)
|
||||
im.save(out)
|
||||
reread = Image.open(out)
|
||||
self.assertEqual(reread.info["version"], b"GIF87a")
|
||||
|
||||
# Test that a GIF89a image is also saved in that format
|
||||
im.info["version"] = "GIF89a"
|
||||
im.save(out)
|
||||
reread = Image.open(out)
|
||||
self.assertEqual(reread.info["version"], b"GIF87a")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user