Skip to content

Commit

Permalink
Merge pull request #5844 from radarhere/numpy_array
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Nov 21, 2021
2 parents e1eefe4 + 83c42fc commit 059503b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/PIL/Image.py
Expand Up @@ -656,6 +656,10 @@ def _repr_png_(self):
raise ValueError("Could not save to PNG for display") from e
return b.getvalue()

class _ArrayData:
def __init__(self, new):
self.__array_interface__ = new

def __array__(self, dtype=None):
# numpy array interface support
import numpy as np
Expand All @@ -672,10 +676,7 @@ def __array__(self, dtype=None):
else:
new["data"] = self.tobytes()

class ArrayData:
__array_interface__ = new

return np.array(ArrayData(), dtype)
return np.array(self._ArrayData(new), dtype)

def __getstate__(self):
return [self.info, self.mode, self.size, self.getpalette(), self.tobytes()]
Expand Down

0 comments on commit 059503b

Please sign in to comment.