mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Raise ValueError when trying to save empty image
This commit is contained in:
parent
1bc0e1bb9d
commit
ae8de77721
|
@ -68,6 +68,13 @@ class TestFileJpeg:
|
|||
assert im.format == "JPEG"
|
||||
assert im.get_format_mimetype() == "image/jpeg"
|
||||
|
||||
@pytest.mark.parametrize("size", ((1, 0), (0, 1), (0, 0)))
|
||||
def test_zero(self, size, tmp_path):
|
||||
f = str(tmp_path / "temp.jpg")
|
||||
im = Image.new("RGB", size)
|
||||
with pytest.raises(ValueError):
|
||||
im.save(f)
|
||||
|
||||
def test_app(self):
|
||||
# Test APP/COM reader (@PIL135)
|
||||
with Image.open(TEST_FILE) as im:
|
||||
|
|
|
@ -656,7 +656,7 @@ class TestImage:
|
|||
temp_file = str(tmp_path / "temp.jpg")
|
||||
|
||||
im = Image.new("RGB", (0, 0))
|
||||
with pytest.raises(SystemError):
|
||||
with pytest.raises(ValueError):
|
||||
im.save(temp_file)
|
||||
|
||||
assert not os.path.exists(temp_file)
|
||||
|
|
|
@ -626,6 +626,8 @@ def get_sampling(im):
|
|||
|
||||
|
||||
def _save(im, fp, filename):
|
||||
if im.width == 0 or im.height == 0:
|
||||
raise ValueError("cannot write empty image as JPEG")
|
||||
|
||||
try:
|
||||
rawmode = RAWMODE[im.mode]
|
||||
|
|
Loading…
Reference in New Issue
Block a user