Skip to content

Commit

Permalink
Simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 23, 2023
1 parent 6215cd3 commit e5c94ec
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,30 +641,23 @@ def _repr_image(self, image_format, **kwargs):
b = io.BytesIO()
try:
self.save(b, image_format, **kwargs)
except Exception as e:
msg = f"Could not save to {image_format} for display"
raise ValueError(msg) from e
except Exception:
return None
return b.getvalue()

def _repr_png_(self):
"""iPython display hook support for PNG format.
:returns: PNG version of the image as bytes
"""
try:
return self._repr_image("PNG", compress_level=1)
except Exception:
return None
return self._repr_image("PNG", compress_level=1)

def _repr_jpeg_(self):
"""iPython display hook support for JPEG format.
:returns: JPEG version of the image as bytes
"""
try:
return self._repr_image("JPEG")
except Exception:
return None
return self._repr_image("JPEG")

@property
def __array_interface__(self):
Expand Down

0 comments on commit e5c94ec

Please sign in to comment.