From 11399b18ce1f77bcede47d9b8db4f5b92c9b4632 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 28 Jul 2017 19:51:26 +1000 Subject: [PATCH] Moved SgiImagePlugin save error to before the start of write operations --- PIL/SgiImagePlugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PIL/SgiImagePlugin.py b/PIL/SgiImagePlugin.py index bca7eb13f9a..d5db91c2fc6 100644 --- a/PIL/SgiImagePlugin.py +++ b/PIL/SgiImagePlugin.py @@ -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())