Skip to content

Commit 8251dbe

Browse files
committed
use "with Image" instead of closing manually
1 parent a3cfd91 commit 8251dbe

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/PIL/EpsImagePlugin.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ def Ghostscript(
157157
startupinfo = subprocess.STARTUPINFO()
158158
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
159159
subprocess.check_call(command, startupinfo=startupinfo)
160-
out_im = Image.open(outfile)
161-
out_im.load()
160+
with Image.open(outfile) as out_im:
161+
out_im.load()
162+
return out_im.im.copy()
162163
finally:
163164
try:
164165
os.unlink(outfile)
@@ -167,10 +168,6 @@ def Ghostscript(
167168
except OSError:
168169
pass
169170

170-
im = out_im.im.copy()
171-
out_im.close()
172-
return im
173-
174171

175172
def _accept(prefix: bytes) -> bool:
176173
return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5)

0 commit comments

Comments
 (0)