From 7da811993add86adbe998a00503fa0a1fe583206 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Mon, 16 Feb 2015 22:02:52 -0600 Subject: [PATCH] Fix compatibility with PIL --- skimage/io/_plugins/pil_plugin.py | 4 ++-- skimage/io/tests/test_pil.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/skimage/io/_plugins/pil_plugin.py b/skimage/io/_plugins/pil_plugin.py index db58c3ba..7ff2e191 100644 --- a/skimage/io/_plugins/pil_plugin.py +++ b/skimage/io/_plugins/pil_plugin.py @@ -181,14 +181,14 @@ def ndarray_to_pil(arr, format_str=None): try: im.frombytes(arr.tobytes(), 'raw', mode) except AttributeError: - im.frombytes(arr.tostring(), 'raw', mode) + im.fromstring(arr.tostring(), 'raw', mode) else: try: im = Image.frombytes(mode, (arr.shape[1], arr.shape[0]), arr.tobytes()) except AttributeError: - im = Image.frombytes(mode, (arr.shape[1], arr.shape[0]), + im = Image.fromstring(mode, (arr.shape[1], arr.shape[0]), arr.tostring()) return im diff --git a/skimage/io/tests/test_pil.py b/skimage/io/tests/test_pil.py index 37395b73..780c66e0 100644 --- a/skimage/io/tests/test_pil.py +++ b/skimage/io/tests/test_pil.py @@ -195,7 +195,10 @@ def test_cmyk(): fname = f.name f.close() img.save(fname) - img.close() + try: + img.close() + except AttributeError: # `close` not available on PIL + pass new = imread(fname) @@ -231,4 +234,4 @@ class TestSaveTIF: yield self.roundtrip, dtype, x if __name__ == "__main__": - run_module_suite() \ No newline at end of file + run_module_suite()