Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/patch-2
Browse files Browse the repository at this point in the history
Added test and flush file pointer
  • Loading branch information
farizrahman4u committed Jul 30, 2021
2 parents feb3103 + 9125631 commit c42e6ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Tests/test_file_sgi.py
Expand Up @@ -73,6 +73,13 @@ def roundtrip(img):
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))

Expand Down
3 changes: 3 additions & 0 deletions src/PIL/SgiImagePlugin.py
Expand Up @@ -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
Expand Down

0 comments on commit c42e6ba

Please sign in to comment.