From 96c5a4c5438c9f95acb47c530935e9abc8d1c31a Mon Sep 17 00:00:00 2001 From: Riley Lahd Date: Thu, 14 Mar 2019 14:40:31 -0600 Subject: [PATCH] Add test for disposal mode 2 gifs --- Tests/test_file_gif.py | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 6a4b14d40..9b0d61541 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -1,6 +1,6 @@ from .helper import unittest, PillowTestCase, hopper, netpbm_available -from PIL import Image, ImagePalette, GifImagePlugin +from PIL import Image, ImagePalette, GifImagePlugin, ImageDraw from io import BytesIO @@ -315,6 +315,55 @@ class TestFileGif(PillowTestCase): img.seek(img.tell() + 1) self.assertEqual(img.disposal_method, i+1) + def test_dispose2_diff(self): + out = self.tempfile('temp.gif') + # 4 backgrounds: White, Grey, Black, Red + im_list = [ + Image.new('RGB', (100, 100), '#fff'), + Image.new('RGB', (100, 100), '#999'), + Image.new('RGB', (100, 100), '#000'), + Image.new('RGB', (100, 100), '#f00'), + ] + # Red circle in center of each frame + for img in im_list: + d = ImageDraw.Draw(img) + d.ellipse([(40,40),(60,60)], fill='#f00') + + # check per frame disposal + im_list[0].save( + out, + save_all=True, + append_images=im_list[1:], + disposal=2 + ) + + img = Image.open(out) + top_left_pixels = [] + center_pixels = [] + + # # Get pixel in top left + # rgb_img = img.convert('RGB') + # r, g, b = rgb_img.getpixel((1,1)) + # top_left_pixels += [(r,g,b)] + # r, g, b = rgb_img.getpixel((50,50)) + # center_pixels += [(r,g,b)] + + for i in range(3): + rgb_img = img.convert('RGB') + # Get pixel in top left + r, g, b = rgb_img.getpixel((1,1)) + top_left_pixels += [(r,g,b)] + # Get pixel in center + r, g, b = rgb_img.getpixel((50,50)) + center_pixels += [(r,g,b)] + for prev in top_left_pixels[:i]: + # Change background every frame + self.assertNotEqual((r,g,b), prev) + for prev in center_pixels[:i]: + # Center remains red every frame + self.assertEqual((r,g,b), (255,0,0)) + img.seek(img.tell() + 1) + def test_iss634(self): img = Image.open("Tests/images/iss634.gif") # seek to the second frame