Merge pull request #3501 from pirate486743186/patch-2

Add APNG extension to PNG plugin
This commit is contained in:
Hugo 2018-12-29 16:55:07 +02:00 committed by GitHub
commit 454fdd7800
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

BIN
Tests/images/iss634.apng Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

View File

@ -6,6 +6,12 @@ from io import BytesIO
import zlib
import sys
try:
from PIL import _webp
HAVE_WEBP = True
except ImportError:
HAVE_WEBP = False
codecs = dir(Image.core)
@ -579,6 +585,13 @@ class TestFilePng(PillowTestCase):
self.assertIsInstance(im.text, dict)
ImageFile.LOAD_TRUNCATED_IMAGES = False
@unittest.skipUnless(HAVE_WEBP and _webp.HAVE_WEBPANIM,
"WebP support not installed with animation")
def test_apng(self):
im = Image.open("Tests/images/iss634.apng")
expected = Image.open("Tests/images/iss634.webp")
self.assert_image_similar(im, expected, 0.23)
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or macOS")
class TestTruncatedPngPLeaks(PillowLeakTestCase):

View File

@ -526,6 +526,19 @@ class PngStream(ChunkStream):
return s
# APNG chunks
def chunk_acTL(self, pos, length):
s = ImageFile._safe_read(self.fp, length)
return s
def chunk_fcTL(self, pos, length):
s = ImageFile._safe_read(self.fp, length)
return s
def chunk_fdAT(self, pos, length):
s = ImageFile._safe_read(self.fp, length)
return s
# --------------------------------------------------------------------
# PNG reader
@ -892,6 +905,7 @@ def getchunks(im, **params):
Image.register_open(PngImageFile.format, PngImageFile, _accept)
Image.register_save(PngImageFile.format, _save)
Image.register_extension(PngImageFile.format, ".png")
Image.register_extensions(PngImageFile.format, [".png", ".apng"])
Image.register_mime(PngImageFile.format, "image/png")
Image.register_mime(PngImageFile.format, "image/apng")