Fix compatibility with PIL

This commit is contained in:
Tony S Yu
2015-02-16 22:02:52 -06:00
parent a4e4612ad7
commit 7da811993a
2 changed files with 7 additions and 4 deletions
+2 -2
View File
@@ -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
+5 -2
View File
@@ -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()
run_module_suite()