Merge pull request #3190 from radarhere/mimetype

Added ImageFile get_format_mimetype method
This commit is contained in:
Hugo 2018-07-01 21:19:57 +03:00 committed by GitHub
commit d97e16c903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 0 deletions

View File

@ -48,6 +48,7 @@ class TestFileJpeg(PillowTestCase):
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "JPEG")
self.assertEqual(im.get_format_mimetype(), "image/jpeg")
def test_app(self):
# Test APP/COM reader (@PIL135)

View File

@ -13,6 +13,7 @@ class TestFilePixar(PillowTestCase):
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "PIXAR")
self.assertIsNone(im.get_format_mimetype())
im2 = hopper()
self.assert_image_similar(im, im2, 4.8)

View File

@ -223,6 +223,13 @@ class TestPyDecoder(PillowTestCase):
im.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)]
self.assertRaises(ValueError, im.load)
def test_no_format(self):
buf = BytesIO(b'\x00'*255)
im = MockImageFile(buf)
self.assertIsNone(im.format)
self.assertIsNone(im.get_format_mimetype())
if __name__ == '__main__':
unittest.main()

View File

@ -118,6 +118,11 @@ class ImageFile(Image.Image):
pass
def get_format_mimetype(self):
if self.format is None:
return
return Image.MIME.get(self.format.upper())
def verify(self):
"Check file integrity"