diff --git a/Tests/test_fontfile.py b/Tests/test_fontfile.py new file mode 100644 index 000000000..ce1e02f63 --- /dev/null +++ b/Tests/test_fontfile.py @@ -0,0 +1,12 @@ +from __future__ import annotations +import pytest + +from PIL import FontFile + + +def test_save(tmp_path): + tempname = str(tmp_path / "temp.pil") + + font = FontFile.FontFile() + with pytest.raises(ValueError): + font.save(tempname) diff --git a/src/PIL/FontFile.py b/src/PIL/FontFile.py index 9f6437779..3ec1ae819 100644 --- a/src/PIL/FontFile.py +++ b/src/PIL/FontFile.py @@ -118,6 +118,9 @@ class FontFile: self.compile() # font data + if not self.bitmap: + msg = "No bitmap created" + raise ValueError(msg) self.bitmap.save(os.path.splitext(filename)[0] + ".pbm", "PNG") # font metrics