Added exception explaining that _repr_png_ saves to PNG

This commit is contained in:
Andrew Murray 2020-12-27 15:36:16 +11:00
parent b48cfa747c
commit fdce845364
2 changed files with 10 additions and 1 deletions

View File

@ -537,6 +537,12 @@ class TestFilePng:
assert repr_png.format == "PNG"
assert_image_equal(im, repr_png)
def test_repr_png_error(self):
im = hopper("F")
with pytest.raises(ValueError):
im._repr_png_()
def test_chunk_order(self, tmp_path):
with Image.open("Tests/images/icc_profile.png") as im:
test_file = str(tmp_path / "temp.png")

View File

@ -670,7 +670,10 @@ class Image:
:returns: png version of the image as bytes
"""
b = io.BytesIO()
self.save(b, "PNG")
try:
self.save(b, "PNG")
except Exception as e:
raise ValueError("Could not save to PNG for display") from e
return b.getvalue()
@property