Merge pull request #7242 from radarhere/repr_png

Prioritise speed in _repr_png_
This commit is contained in:
Hugo van Kemenade 2023-06-30 08:29:47 +03:00 committed by GitHub
commit bd795d7c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -632,7 +632,7 @@ class Image:
) )
) )
def _repr_image(self, image_format): def _repr_image(self, image_format, **kwargs):
"""Helper function for iPython display hook. """Helper function for iPython display hook.
:param image_format: Image format. :param image_format: Image format.
@ -640,7 +640,7 @@ class Image:
""" """
b = io.BytesIO() b = io.BytesIO()
try: try:
self.save(b, image_format) self.save(b, image_format, **kwargs)
except Exception as e: except Exception as e:
msg = f"Could not save to {image_format} for display" msg = f"Could not save to {image_format} for display"
raise ValueError(msg) from e raise ValueError(msg) from e
@ -651,7 +651,7 @@ class Image:
:returns: PNG version of the image as bytes :returns: PNG version of the image as bytes
""" """
return self._repr_image("PNG") return self._repr_image("PNG", compress_level=1)
def _repr_jpeg_(self): def _repr_jpeg_(self):
"""iPython display hook support for JPEG format. """iPython display hook support for JPEG format.