mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-05 20:33:24 +03:00
Added GifImagePlugin tests
This commit is contained in:
parent
ecebedba7f
commit
a5917b3fa3
|
@ -341,7 +341,7 @@ def get_local_header(fp, im, offset=(0, 0)):
|
||||||
transparent_color_exists = False
|
transparent_color_exists = False
|
||||||
|
|
||||||
if "duration" in im.encoderinfo:
|
if "duration" in im.encoderinfo:
|
||||||
duration = im.encoderinfo["duration"] / 10
|
duration = int(im.encoderinfo["duration"] / 10)
|
||||||
else:
|
else:
|
||||||
duration = 0
|
duration = 0
|
||||||
if transparent_color_exists or 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:
|
if "loop" in im.encoderinfo:
|
||||||
number_of_loops = im.encoderinfo["loop"]
|
number_of_loops = im.encoderinfo["loop"]
|
||||||
fp.write(b"!" +
|
fp.write(b"!" +
|
||||||
o8(255) + o8(11) + # extension intro
|
o8(255) + # extension intro
|
||||||
|
o8(11) +
|
||||||
b"NETSCAPE2.0" +
|
b"NETSCAPE2.0" +
|
||||||
o8(3) +
|
o8(3) +
|
||||||
o8(1) +
|
o8(1) +
|
||||||
|
|
|
@ -169,6 +169,33 @@ class TestFileGif(PillowTestCase):
|
||||||
# first frame
|
# first frame
|
||||||
self.assertEqual(img.histogram()[img.info['transparency']], 0)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user