mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-24 16:24:11 +03:00
Detect whether mimetype is image/png or image/apng
This commit is contained in:
parent
e32e3fdbeb
commit
97ae0c42b1
|
@ -86,6 +86,7 @@ class TestFilePng(PillowTestCase):
|
||||||
self.assertEqual(im.mode, "RGB")
|
self.assertEqual(im.mode, "RGB")
|
||||||
self.assertEqual(im.size, (128, 128))
|
self.assertEqual(im.size, (128, 128))
|
||||||
self.assertEqual(im.format, "PNG")
|
self.assertEqual(im.format, "PNG")
|
||||||
|
self.assertEqual(im.get_format_mimetype(), 'image/png')
|
||||||
|
|
||||||
hopper("1").save(test_file)
|
hopper("1").save(test_file)
|
||||||
Image.open(test_file)
|
Image.open(test_file)
|
||||||
|
@ -589,6 +590,8 @@ class TestFilePng(PillowTestCase):
|
||||||
"WebP support not installed with animation")
|
"WebP support not installed with animation")
|
||||||
def test_apng(self):
|
def test_apng(self):
|
||||||
im = Image.open("Tests/images/iss634.apng")
|
im = Image.open("Tests/images/iss634.apng")
|
||||||
|
self.assertEqual(im.get_format_mimetype(), 'image/apng')
|
||||||
|
|
||||||
expected = Image.open("Tests/images/iss634.webp")
|
expected = Image.open("Tests/images/iss634.webp")
|
||||||
self.assert_image_similar(im, expected, 0.23)
|
self.assert_image_similar(im, expected, 0.23)
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,8 @@ class ImageFile(Image.Image):
|
||||||
|
|
||||||
self._min_frame = 0
|
self._min_frame = 0
|
||||||
|
|
||||||
|
self.custom_mimetype = None
|
||||||
|
|
||||||
self.tile = None
|
self.tile = None
|
||||||
self.readonly = 1 # until we know better
|
self.readonly = 1 # until we know better
|
||||||
|
|
||||||
|
@ -120,7 +122,7 @@ class ImageFile(Image.Image):
|
||||||
def get_format_mimetype(self):
|
def get_format_mimetype(self):
|
||||||
if self.format is None:
|
if self.format is None:
|
||||||
return
|
return
|
||||||
return Image.MIME.get(self.format.upper())
|
return self.custom_mimetype or Image.MIME.get(self.format.upper())
|
||||||
|
|
||||||
def verify(self):
|
def verify(self):
|
||||||
"Check file integrity"
|
"Check file integrity"
|
||||||
|
|
|
@ -296,6 +296,7 @@ class PngStream(ChunkStream):
|
||||||
self.im_mode = None
|
self.im_mode = None
|
||||||
self.im_tile = None
|
self.im_tile = None
|
||||||
self.im_palette = None
|
self.im_palette = None
|
||||||
|
self.im_custom_mimetype = None
|
||||||
|
|
||||||
self.text_memory = 0
|
self.text_memory = 0
|
||||||
|
|
||||||
|
@ -529,6 +530,7 @@ class PngStream(ChunkStream):
|
||||||
# APNG chunks
|
# APNG chunks
|
||||||
def chunk_acTL(self, pos, length):
|
def chunk_acTL(self, pos, length):
|
||||||
s = ImageFile._safe_read(self.fp, length)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
|
self.im_custom_mimetype = 'image/apng'
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_fcTL(self, pos, length):
|
def chunk_fcTL(self, pos, length):
|
||||||
|
@ -594,6 +596,7 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
self.info = self.png.im_info
|
self.info = self.png.im_info
|
||||||
self._text = None
|
self._text = None
|
||||||
self.tile = self.png.im_tile
|
self.tile = self.png.im_tile
|
||||||
|
self.custom_mimetype = self.png.im_custom_mimetype
|
||||||
|
|
||||||
if self.png.im_palette:
|
if self.png.im_palette:
|
||||||
rawmode, data = 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_extensions(PngImageFile.format, [".png", ".apng"])
|
||||||
|
|
||||||
Image.register_mime(PngImageFile.format, "image/png")
|
Image.register_mime(PngImageFile.format, "image/png")
|
||||||
Image.register_mime(PngImageFile.format, "image/apng")
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user