use "with Image" instead of closing manually

This commit is contained in:
Yay295 2024-08-04 00:48:12 -05:00
parent 3ccecd91ce
commit 00bbd4a5b9

View File

@ -157,8 +157,9 @@ def Ghostscript(
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.check_call(command, startupinfo=startupinfo) subprocess.check_call(command, startupinfo=startupinfo)
out_im = Image.open(outfile) with Image.open(outfile) as out_im:
out_im.load() out_im.load()
return out_im.im.copy()
finally: finally:
try: try:
os.unlink(outfile) os.unlink(outfile)
@ -167,10 +168,6 @@ def Ghostscript(
except OSError: except OSError:
pass pass
im = out_im.im.copy()
out_im.close()
return im
def _accept(prefix: bytes) -> bool: def _accept(prefix: bytes) -> bool:
return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5) return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5)