diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index be52b3bd1..408a76444 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -86,6 +86,7 @@ class TestFilePng(PillowTestCase): self.assertEqual(im.mode, "RGB") self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "PNG") + self.assertEqual(im.get_format_mimetype(), 'image/png') hopper("1").save(test_file) Image.open(test_file) @@ -589,6 +590,8 @@ class TestFilePng(PillowTestCase): "WebP support not installed with animation") def test_apng(self): im = Image.open("Tests/images/iss634.apng") + self.assertEqual(im.get_format_mimetype(), 'image/apng') + expected = Image.open("Tests/images/iss634.webp") self.assert_image_similar(im, expected, 0.23) diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 915557a57..bcc910853 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -79,6 +79,8 @@ class ImageFile(Image.Image): self._min_frame = 0 + self.custom_mimetype = None + self.tile = None self.readonly = 1 # until we know better @@ -120,7 +122,7 @@ class ImageFile(Image.Image): def get_format_mimetype(self): if self.format is None: return - return Image.MIME.get(self.format.upper()) + return self.custom_mimetype or Image.MIME.get(self.format.upper()) def verify(self): "Check file integrity" diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 04161a56c..d8ef56d73 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -296,6 +296,7 @@ class PngStream(ChunkStream): self.im_mode = None self.im_tile = None self.im_palette = None + self.im_custom_mimetype = None self.text_memory = 0 @@ -529,6 +530,7 @@ class PngStream(ChunkStream): # APNG chunks def chunk_acTL(self, pos, length): s = ImageFile._safe_read(self.fp, length) + self.im_custom_mimetype = 'image/apng' return s def chunk_fcTL(self, pos, length): @@ -594,6 +596,7 @@ class PngImageFile(ImageFile.ImageFile): self.info = self.png.im_info self._text = None self.tile = self.png.im_tile + self.custom_mimetype = self.png.im_custom_mimetype if self.png.im_palette: rawmode, data = self.png.im_palette @@ -908,4 +911,3 @@ Image.register_save(PngImageFile.format, _save) Image.register_extensions(PngImageFile.format, [".png", ".apng"]) Image.register_mime(PngImageFile.format, "image/png") -Image.register_mime(PngImageFile.format, "image/apng")