Skip to content

Commit 6b9ce76

Browse files
committed
Compatibility with older versions of PIL that don't have frombytes.
1 parent 64f32d4 commit 6b9ce76

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

nibabel/dft.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ def __getattribute__(self, name):
124124

125125
def as_png(self, index=None, scale_to_slice=True):
126126
import PIL.Image
127+
# For compatibility with older versions of PIL that did not
128+
# have `frombytes`:
129+
if hasattr(PIL.Image, 'frombytes'):
130+
frombytes = PIL.Image.frombytes
131+
else:
132+
frombytes = PIL.Image.fromstring
133+
127134
if index is None:
128135
index = len(self.storage_instances) // 2
129136
d = self.storage_instances[index].dicom()
@@ -138,8 +145,9 @@ def as_png(self, index=None, scale_to_slice=True):
138145
max = data.max()
139146
data = data * 255 / (max - min)
140147
data = data.astype(numpy.uint8)
141-
im = PIL.Image.frombytes('L', (self.rows, self.columns),
142-
data.tostring())
148+
im = frombytes('L', (self.rows, self.columns),
149+
data.tostring())
150+
143151
s = BytesIO()
144152
im.save(s, 'PNG')
145153
return s.getvalue()

0 commit comments

Comments
 (0)