mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Added ImageFile get_format_mimetype method
This commit is contained in:
parent
1ffc67e70b
commit
6793b5bbd5
|
@ -48,6 +48,7 @@ class TestFileJpeg(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, "JPEG")
|
self.assertEqual(im.format, "JPEG")
|
||||||
|
self.assertEqual(im.get_format_mimetype(), "image/jpeg")
|
||||||
|
|
||||||
def test_app(self):
|
def test_app(self):
|
||||||
# Test APP/COM reader (@PIL135)
|
# Test APP/COM reader (@PIL135)
|
||||||
|
|
|
@ -13,6 +13,7 @@ class TestFilePixar(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, "PIXAR")
|
self.assertEqual(im.format, "PIXAR")
|
||||||
|
self.assertIsNone(im.get_format_mimetype())
|
||||||
|
|
||||||
im2 = hopper()
|
im2 = hopper()
|
||||||
self.assert_image_similar(im, im2, 4.8)
|
self.assert_image_similar(im, im2, 4.8)
|
||||||
|
|
|
@ -223,6 +223,13 @@ class TestPyDecoder(PillowTestCase):
|
||||||
im.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)]
|
im.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)]
|
||||||
self.assertRaises(ValueError, im.load)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -118,6 +118,11 @@ class ImageFile(Image.Image):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_format_mimetype(self):
|
||||||
|
if self.format is None:
|
||||||
|
return
|
||||||
|
return Image.MIME.get(self.format.upper())
|
||||||
|
|
||||||
def verify(self):
|
def verify(self):
|
||||||
"Check file integrity"
|
"Check file integrity"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user