From a5917b3fa36fb2128a5451fe355b287056042f7f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 4 Apr 2015 11:45:30 +1100 Subject: [PATCH] Added GifImagePlugin tests --- PIL/GifImagePlugin.py | 5 +++-- Tests/test_file_gif.py | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 6c1d53a1c..69df28b30 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -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) + diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 2ce728801..1378fb3f6 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -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()