mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
If n_frames is known, then use when determining is_animated
This commit is contained in:
parent
8e8643d1ac
commit
ce999ff302
|
@ -102,6 +102,9 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
@property
|
@property
|
||||||
def is_animated(self):
|
def is_animated(self):
|
||||||
if self._is_animated is None:
|
if self._is_animated is None:
|
||||||
|
if self._n_frames is not None:
|
||||||
|
self._is_animated = self._n_frames != 1
|
||||||
|
else:
|
||||||
current = self.tell()
|
current = self.tell()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -931,6 +931,9 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
@property
|
@property
|
||||||
def is_animated(self):
|
def is_animated(self):
|
||||||
if self._is_animated is None:
|
if self._is_animated is None:
|
||||||
|
if self._n_frames is not None:
|
||||||
|
self._is_animated = self._n_frames != 1
|
||||||
|
else:
|
||||||
current = self.tell()
|
current = self.tell()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -208,13 +208,18 @@ class TestFileGif(PillowTestCase):
|
||||||
self.assertEqual(framecount, 5)
|
self.assertEqual(framecount, 5)
|
||||||
|
|
||||||
def test_n_frames(self):
|
def test_n_frames(self):
|
||||||
im = Image.open(TEST_GIF)
|
for path, n_frames in [
|
||||||
self.assertEqual(im.n_frames, 1)
|
[TEST_GIF, 1],
|
||||||
self.assertFalse(im.is_animated)
|
['Tests/images/iss634.gif', 42]
|
||||||
|
]:
|
||||||
|
# Test is_animated before n_frames
|
||||||
|
im = Image.open(path)
|
||||||
|
self.assertEqual(im.is_animated, n_frames != 1)
|
||||||
|
|
||||||
im = Image.open("Tests/images/iss634.gif")
|
# Test is_animated after n_frames
|
||||||
self.assertEqual(im.n_frames, 42)
|
im = Image.open(path)
|
||||||
self.assertTrue(im.is_animated)
|
self.assertEqual(im.n_frames, n_frames)
|
||||||
|
self.assertEqual(im.is_animated, n_frames != 1)
|
||||||
|
|
||||||
def test_eoferror(self):
|
def test_eoferror(self):
|
||||||
im = Image.open(TEST_GIF)
|
im = Image.open(TEST_GIF)
|
||||||
|
|
|
@ -216,13 +216,18 @@ class TestFileTiff(PillowTestCase):
|
||||||
im.getextrema(), (-3.140936851501465, 3.140684127807617))
|
im.getextrema(), (-3.140936851501465, 3.140684127807617))
|
||||||
|
|
||||||
def test_n_frames(self):
|
def test_n_frames(self):
|
||||||
im = Image.open('Tests/images/multipage-lastframe.tif')
|
for path, n_frames in [
|
||||||
self.assertEqual(im.n_frames, 1)
|
['Tests/images/multipage-lastframe.tif', 1],
|
||||||
self.assertFalse(im.is_animated)
|
['Tests/images/multipage.tiff', 3]
|
||||||
|
]:
|
||||||
|
# Test is_animated before n_frames
|
||||||
|
im = Image.open(path)
|
||||||
|
self.assertEqual(im.is_animated, n_frames != 1)
|
||||||
|
|
||||||
im = Image.open('Tests/images/multipage.tiff')
|
# Test is_animated after n_frames
|
||||||
self.assertEqual(im.n_frames, 3)
|
im = Image.open(path)
|
||||||
self.assertTrue(im.is_animated)
|
self.assertEqual(im.n_frames, n_frames)
|
||||||
|
self.assertEqual(im.is_animated, n_frames != 1)
|
||||||
|
|
||||||
def test_eoferror(self):
|
def test_eoferror(self):
|
||||||
im = Image.open('Tests/images/multipage-lastframe.tif')
|
im = Image.open('Tests/images/multipage-lastframe.tif')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user