mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use Pillow's Image context manager to close image file
This commit is contained in:
parent
47cd262b3e
commit
8f30ec9407
@ -42,12 +42,8 @@ def get_image_size(filename: str) -> Tuple[int, int]:
|
||||
size = None
|
||||
|
||||
if size is None and Image: # fallback to Pillow
|
||||
im = Image.open(filename)
|
||||
size = im.size
|
||||
try:
|
||||
im.fp.close()
|
||||
except Exception:
|
||||
pass
|
||||
with Image.open(filename) as im:
|
||||
size = im.size
|
||||
|
||||
return size
|
||||
except Exception:
|
||||
|
Loading…
Reference in New Issue
Block a user