Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_sanity(self) -> None:
def test_zero(self, size: tuple[int, int], tmp_path: Path) -> None:
f = tmp_path / "temp.jpg"
im = Image.new("RGB", size)
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="cannot write empty image"):
im.save(f)

def test_app(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ def test_save_single_strip(
def test_save_zero(self, compression: str | None, tmp_path: Path) -> None:
im = Image.new("RGB", (0, 0))
out = tmp_path / "temp.tif"
with pytest.raises(SystemError):
with pytest.raises(ValueError, match="cannot write empty image"):
im.save(out, compression=compression)

def test_save_many_compressed(self, tmp_path: Path) -> None:
Expand Down
4 changes: 0 additions & 4 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,6 @@ def get_sampling(im: Image.Image) -> int:


def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
if im.width == 0 or im.height == 0:
msg = "cannot write empty image as JPEG"
raise ValueError(msg)

try:
rawmode = RAWMODE[im.mode]
except KeyError as e:
Expand Down
4 changes: 4 additions & 0 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) {
if (!im) {
return NULL;
}
if (im->xsize == 0 || im->ysize == 0) {
PyErr_SetString(PyExc_ValueError, "cannot write empty image");
return NULL;
}

encoder->im = im;

Expand Down
Loading