Added GifImagePlugin tests

This commit is contained in:
Andrew Murray 2015-04-04 11:45:30 +11:00
parent ecebedba7f
commit a5917b3fa3
2 changed files with 30 additions and 2 deletions

View File

@ -341,7 +341,7 @@ def get_local_header(fp, im, offset=(0, 0)):
transparent_color_exists = False
if "duration" in im.encoderinfo:
duration = im.encoderinfo["duration"] / 10
duration = int(im.encoderinfo["duration"] / 10)
else:
duration = 0
if transparent_color_exists or duration != 0:
@ -360,7 +360,8 @@ def get_local_header(fp, im, offset=(0, 0)):
if "loop" in im.encoderinfo:
number_of_loops = im.encoderinfo["loop"]
fp.write(b"!" +
o8(255) + o8(11) + # extension intro
o8(255) + # extension intro
o8(11) +
b"NETSCAPE2.0" +
o8(3) +
o8(1) +

View File

@ -169,6 +169,33 @@ class TestFileGif(PillowTestCase):
# first frame
self.assertEqual(img.histogram()[img.info['transparency']], 0)
def test_duration(self):
duration = 1000
out = self.tempfile('temp.gif')
fp = open(out, "wb")
im = Image.new('L',(100,100),'#000')
for s in GifImagePlugin.getheader(im)[0] + GifImagePlugin.getdata(im, duration=duration):
fp.write(s)
fp.write(b";")
fp.close()
reread = Image.open(out)
self.assertEqual(reread.info['duration'], duration)
def test_number_of_loops(self):
number_of_loops = 2
out = self.tempfile('temp.gif')
fp = open(out, "wb")
im = Image.new('L',(100,100),'#000')
for s in GifImagePlugin.getheader(im)[0] + GifImagePlugin.getdata(im, loop=number_of_loops):
fp.write(s)
fp.write(b";")
fp.close()
reread = Image.open(out)
self.assertEqual(reread.info['loop'], number_of_loops)
if __name__ == '__main__':
unittest.main()