Use context managers to ensure Pillow images are closed

This commit is contained in:
James R. Barlow
2019-09-03 17:19:12 -07:00
parent c8d6ea6b10
commit feff1e38bb
8 changed files with 45 additions and 45 deletions
+2 -2
View File
@@ -233,8 +233,8 @@ def _generate_null_hocr(output_hocr, output_sidecar, image):
the same size as the input image."""
from PIL import Image
im = Image.open(image)
w, h = im.size
with Image.open(image) as im:
w, h = im.size
with open(output_hocr, 'w', encoding="utf-8") as f:
f.write(HOCR_TEMPLATE.format(w, h))