mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
commit
975fccafc7
|
@ -14,12 +14,14 @@ class TestFilePpm(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, "PPM")
|
self.assertEqual(im.format, "PPM")
|
||||||
|
self.assertEqual(im.get_format_mimetype(), "image/x-portable-pixmap")
|
||||||
|
|
||||||
def test_16bit_pgm(self):
|
def test_16bit_pgm(self):
|
||||||
im = Image.open('Tests/images/16_bit_binary.pgm')
|
im = Image.open('Tests/images/16_bit_binary.pgm')
|
||||||
im.load()
|
im.load()
|
||||||
self.assertEqual(im.mode, 'I')
|
self.assertEqual(im.mode, 'I')
|
||||||
self.assertEqual(im.size, (20, 100))
|
self.assertEqual(im.size, (20, 100))
|
||||||
|
self.assertEqual(im.get_format_mimetype(), "image/x-portable-graymap")
|
||||||
|
|
||||||
tgt = Image.open('Tests/images/16_bit_binary_pgm.png')
|
tgt = Image.open('Tests/images/16_bit_binary_pgm.png')
|
||||||
self.assert_image_equal(im, tgt)
|
self.assert_image_equal(im, tgt)
|
||||||
|
@ -49,3 +51,16 @@ class TestFilePpm(PillowTestCase):
|
||||||
|
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(IOError):
|
||||||
Image.open('Tests/images/negative_size.ppm')
|
Image.open('Tests/images/negative_size.ppm')
|
||||||
|
|
||||||
|
def test_mimetypes(self):
|
||||||
|
path = self.tempfile('temp.pgm')
|
||||||
|
|
||||||
|
with open(path, 'w') as f:
|
||||||
|
f.write("P4\n128 128\n255")
|
||||||
|
im = Image.open(path)
|
||||||
|
self.assertEqual(im.get_format_mimetype(), "image/x-portable-bitmap")
|
||||||
|
|
||||||
|
with open(path, 'w') as f:
|
||||||
|
f.write("PyCMYK\n128 128\n255")
|
||||||
|
im = Image.open(path)
|
||||||
|
self.assertEqual(im.get_format_mimetype(), "image/x-portable-anymap")
|
||||||
|
|
|
@ -70,7 +70,14 @@ class PpmImageFile(ImageFile.ImageFile):
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
if s != b"P":
|
if s != b"P":
|
||||||
raise SyntaxError("not a PPM file")
|
raise SyntaxError("not a PPM file")
|
||||||
mode = MODES[self._token(s)]
|
magic_number = self._token(s)
|
||||||
|
mode = MODES[magic_number]
|
||||||
|
|
||||||
|
self.custom_mimetype = {
|
||||||
|
b"P4": "image/x-portable-bitmap",
|
||||||
|
b"P5": "image/x-portable-graymap",
|
||||||
|
b"P6": "image/x-portable-pixmap",
|
||||||
|
}.get(magic_number)
|
||||||
|
|
||||||
if mode == "1":
|
if mode == "1":
|
||||||
self.mode = "1"
|
self.mode = "1"
|
||||||
|
@ -158,3 +165,5 @@ Image.register_open(PpmImageFile.format, PpmImageFile, _accept)
|
||||||
Image.register_save(PpmImageFile.format, _save)
|
Image.register_save(PpmImageFile.format, _save)
|
||||||
|
|
||||||
Image.register_extensions(PpmImageFile.format, [".pbm", ".pgm", ".ppm"])
|
Image.register_extensions(PpmImageFile.format, [".pbm", ".pgm", ".ppm"])
|
||||||
|
|
||||||
|
Image.register_mime(PpmImageFile.format, "image/x-portable-anymap")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user