From c930133982aa51e0168d35f36716d16b9c436a12 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 12 Feb 2014 12:17:26 +0200 Subject: [PATCH 1/2] Use frombytes instead of fromstring on PIL images, since the latter is now deprecated --- skimage/io/_plugins/pil_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/io/_plugins/pil_plugin.py b/skimage/io/_plugins/pil_plugin.py index c6e968dc..3d627852 100644 --- a/skimage/io/_plugins/pil_plugin.py +++ b/skimage/io/_plugins/pil_plugin.py @@ -109,7 +109,7 @@ def imsave(fname, arr, format_str=None): if not isinstance(fname, string_types) and format_str is None: format_str = "PNG" - img = Image.fromstring(mode, (arr.shape[1], arr.shape[0]), arr.tostring()) + img = Image.frombytes(mode, (arr.shape[1], arr.shape[0]), arr.tostring()) img.save(fname, format=format_str) From b71008a13500154dffffd19d334bcec95cd0dc1d Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 12 Feb 2014 12:59:51 +0200 Subject: [PATCH 2/2] Fix Image.frombytes for older version of Python/PIL --- skimage/io/_plugins/pil_plugin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/skimage/io/_plugins/pil_plugin.py b/skimage/io/_plugins/pil_plugin.py index 3d627852..6dd78035 100644 --- a/skimage/io/_plugins/pil_plugin.py +++ b/skimage/io/_plugins/pil_plugin.py @@ -109,7 +109,13 @@ def imsave(fname, arr, format_str=None): if not isinstance(fname, string_types) and format_str is None: format_str = "PNG" - img = Image.frombytes(mode, (arr.shape[1], arr.shape[0]), arr.tostring()) + try: + img = Image.frombytes(mode, (arr.shape[1], arr.shape[0]), + arr.tostring()) + except AttributeError: + img = Image.fromstring(mode, (arr.shape[1], arr.shape[0]), + arr.tostring()) + img.save(fname, format=format_str)