From 300f1ffc024fb7c7213d94d95963e0963d7e546f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 30 Jul 2021 20:29:07 +1000 Subject: [PATCH 1/2] Added test --- Tests/test_file_sgi.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tests/test_file_sgi.py b/Tests/test_file_sgi.py index 0210dd4f1..6a5d8887d 100644 --- a/Tests/test_file_sgi.py +++ b/Tests/test_file_sgi.py @@ -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)) From 9125631ff04e8925d1ae0f7a310728005f22f73f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 30 Jul 2021 20:25:07 +1000 Subject: [PATCH 2/2] Added flush --- src/PIL/SgiImagePlugin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PIL/SgiImagePlugin.py b/src/PIL/SgiImagePlugin.py index 71e288022..5f1ef6edc 100644 --- a/src/PIL/SgiImagePlugin.py +++ b/src/PIL/SgiImagePlugin.py @@ -193,6 +193,9 @@ def _save(im, fp, filename): for channel in im.split(): fp.write(channel.tobytes("raw", rawmode, 0, orientation)) + if hasattr(fp, "flush"): + fp.flush() + class SGI16Decoder(ImageFile.PyDecoder): _pulls_fd = True