Moved SgiImagePlugin save error to before the start of write operations

This commit is contained in:
Andrew Murray 2017-07-28 19:51:26 +10:00
parent bbe07d4f49
commit 11399b18ce

View File

@ -104,6 +104,11 @@ def _save(im, fp, filename):
z = len(im.mode)
if dim == 1 or dim == 2:
z = 1
# assert we've got the right number of bands.
if len(im.getbands()) != z:
raise ValueError("incorrect number of bands in SGI write: %s vs %s" %
(z, len(im.getbands())))
# Minimum Byte value
pinmin = 0
# Maximum Byte value (255 = 8bits per pixel)
@ -131,11 +136,6 @@ def _save(im, fp, filename):
fp.write(struct.pack('404s', b'')) # dummy
# assert we've got the right number of bands.
if len(im.getbands()) != z:
raise ValueError("incorrect number of bands in SGI write: %s vs %s" %
(z, len(im.getbands())))
for channel in im.split():
fp.write(channel.tobytes())