From 5e3ffb3c2295364b8e108f210885c5eb9b9c23e6 Mon Sep 17 00:00:00 2001 From: "E. McConville" Date: Tue, 19 Jul 2022 08:29:00 -0500 Subject: [PATCH] Fixed #583 - Support strided numpy arrays --- docs/changes.rst | 1 + wand/image.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index b889deed..7f4dc266 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -15,6 +15,7 @@ Version 0.6.9 Unreleased. - Updated :meth:`Image.fx() ` method to raise :class:`~wand.exceptions.WandRuntimeError` if ImageMagick is unable to generate an image. [:issue:`582`] + - Fixed :meth:`Image.from_array() ` classmethod to handle Numpy's strided arrays. [:issue:`582`] .. _changelog-0.6.8: diff --git a/wand/image.py b/wand/image.py index aa2494e9..b74e80bf 100644 --- a/wand/image.py +++ b/wand/image.py @@ -9513,7 +9513,8 @@ def from_array(cls, array, channel_map=None, storage=None): channel_map = 'CMYKA'[0:shape[2]] else: channel_map = 'R' - if hasattr(array, 'ctypes'): + strides = arr_itr.get('strides', None) + if hasattr(array, 'ctypes') and strides is None: data_ptr = array.ctypes.data_as(ctypes.c_void_p) elif hasattr(array, 'tobytes'): data_ptr = array.tobytes()