mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
commit
95e9379f45
10
PIL/Image.py
10
PIL/Image.py
|
@ -598,6 +598,16 @@ class Image:
|
|||
id(self)
|
||||
)
|
||||
|
||||
def _repr_png_(self):
|
||||
""" iPython display hook support
|
||||
|
||||
:returns: png version of the image as bytes
|
||||
"""
|
||||
from io import BytesIO
|
||||
b = BytesIO()
|
||||
self.save(b, 'PNG')
|
||||
return b.getvalue()
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name == "__array_interface__":
|
||||
# numpy array interface support
|
||||
|
|
|
@ -374,6 +374,14 @@ class TestFilePng(PillowTestCase):
|
|||
im = roundtrip(im)
|
||||
self.assertEqual(im.info['icc_profile'], expected_icc)
|
||||
|
||||
def test_repr_png(self):
|
||||
im = hopper()
|
||||
|
||||
repr_png = Image.open(BytesIO(im._repr_png_()))
|
||||
self.assertEqual(repr_png.format, 'PNG')
|
||||
self.assert_image_equal(im, repr_png)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user