diff --git a/Tests/images/rewind.gif b/Tests/images/rewind.gif new file mode 100644 index 000000000..fea03b1d5 Binary files /dev/null and b/Tests/images/rewind.gif differ diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index f1d9d688f..8501ec380 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -293,6 +293,26 @@ class TestFileGif(PillowTestCase): self.assertEqual(color, expected_colors[frame][x], 'frame %i, x %i' % (frame, x)) + def test_rewind(self): + img = Image.open("Tests/images/rewind.gif") + + # Seek forwards to frame 2. This will decode frames 0 and 1. + img.seek(2) + + # Seek back to frame 1. This will rewind to frame 0, then seek + # to frame 1. + img.seek(1) + + # Read data. This should decode frame 0 and then frame 1. + img.getpixel((0,1)) + + expected_colors = [(2, 3), (3, 1)] + for x in range(2): + for y in range(2): + color = img.getpixel((x,y)) + self.assertEqual(color, expected_colors[x][y], + '%ix%i' % (x, y)) + def test_dispose_previous(self): img = Image.open("Tests/images/dispose_prev.gif") try: diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index ecf4c2be5..5c17545cd 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -144,7 +144,7 @@ class GifImageFile(ImageFile.ImageFile): self.disposal_method = 0 else: # ensure that the previous frame was loaded - if not self.im: + if self.tile: self.load() if frame != self.__frame + 1: