Merge pull request #5645 from farizrahman4u/patch-2

Do not close file pointer in SGI save handler
This commit is contained in:
Andrew Murray 2021-07-31 13:53:37 +10:00 committed by GitHub
commit 61419b54d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -73,6 +73,13 @@ def test_write(tmp_path):
img.save(out, format="sgi")
assert_image_equal_tofile(img, out)
out = str(tmp_path / "fp.sgi")
with open(out, "wb") as fp:
img.save(fp)
assert_image_equal_tofile(img, out)
assert not fp.closed
for mode in ("L", "RGB", "RGBA"):
roundtrip(hopper(mode))

View File

@ -193,7 +193,8 @@ def _save(im, fp, filename):
for channel in im.split():
fp.write(channel.tobytes("raw", rawmode, 0, orientation))
fp.close()
if hasattr(fp, "flush"):
fp.flush()
class SGI16Decoder(ImageFile.PyDecoder):