mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-12-04 16:54:28 +03:00
Close image on ImageFont exception (#9304)
This commit is contained in:
commit
da76f6d99b
|
|
@ -127,11 +127,15 @@ class ImageFont:
|
||||||
def _load_pilfont_data(self, file: IO[bytes], image: Image.Image) -> None:
|
def _load_pilfont_data(self, file: IO[bytes], image: Image.Image) -> None:
|
||||||
# check image
|
# check image
|
||||||
if image.mode not in ("1", "L"):
|
if image.mode not in ("1", "L"):
|
||||||
|
image.close()
|
||||||
|
|
||||||
msg = "invalid font image mode"
|
msg = "invalid font image mode"
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
# read PILfont header
|
# read PILfont header
|
||||||
if file.read(8) != b"PILfont\n":
|
if file.read(8) != b"PILfont\n":
|
||||||
|
image.close()
|
||||||
|
|
||||||
msg = "Not a PILfont file"
|
msg = "Not a PILfont file"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
file.readline()
|
file.readline()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user