From 1df63eeb1ae2a8b5f768323d5c544d46880f09be Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 29 Jul 2017 10:20:13 +1000 Subject: [PATCH 1/2] Added file pointer save to SpiderImagePlugin --- PIL/SpiderImagePlugin.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/PIL/SpiderImagePlugin.py b/PIL/SpiderImagePlugin.py index 6730bd104..a821fcf87 100644 --- a/PIL/SpiderImagePlugin.py +++ b/PIL/SpiderImagePlugin.py @@ -267,17 +267,11 @@ def _save(im, fp, filename): raise IOError("Error creating Spider header") # write the SPIDER header - try: - fp = open(filename, 'wb') - except: - raise IOError("Unable to open %s for writing" % filename) fp.writelines(hdr) rawmode = "F;32NF" # 32-bit native floating point ImageFile._save(im, fp, [("raw", (0, 0)+im.size, 0, (rawmode, 0, 1))]) - fp.close() - def _save_spider(im, fp, filename): # get the filename extension and register it with Image From eaffb1414a4752c8f1a2de6eafffc849a68f2cd0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 29 Jul 2017 10:20:19 +1000 Subject: [PATCH 2/2] Added test --- Tests/test_file_spider.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Tests/test_file_spider.py b/Tests/test_file_spider.py index 32f1f55e5..4c95c6e4f 100644 --- a/Tests/test_file_spider.py +++ b/Tests/test_file_spider.py @@ -4,6 +4,8 @@ from PIL import Image from PIL import ImageSequence from PIL import SpiderImagePlugin +import tempfile + TEST_FILE = "Tests/images/hopper.spider" @@ -30,6 +32,21 @@ class TestImageSpider(PillowTestCase): self.assertEqual(im2.size, (128, 128)) self.assertEqual(im2.format, "SPIDER") + def test_tempfile(self): + # Arrange + im = hopper() + + # Act + with tempfile.TemporaryFile() as fp: + im.save(fp, "SPIDER") + + # Assert + fp.seek(0) + reloaded = Image.open(fp) + self.assertEqual(reloaded.mode, "F") + self.assertEqual(reloaded.size, (128, 128)) + self.assertEqual(reloaded.format, "SPIDER") + def test_isSpiderImage(self): self.assertTrue(SpiderImagePlugin.isSpiderImage(TEST_FILE))