Skip to content

Commit 7bd2cdb

Browse files
committed
Fix fallback _load_image() with Pillow 3.x
Fixes Pillow exception on image read when we're installed --without-performance: Exception: tostring() has been removed. Please call tobytes() instead. Found by @andrewmfiorillo.
1 parent 0c8ab25 commit 7bd2cdb

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

openslide/lowlevel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def _load_image(buf, size):
6868
# First reorder the bytes in a pixel from native-endian aRGB to
6969
# big-endian RGBa to work around limitations in RGBa loader
7070
rawmode = (sys.byteorder == 'little') and 'BGRA' or 'ARGB'
71-
buf = PIL.Image.frombuffer('RGBA', size, buf, 'raw', rawmode, 0,
72-
1).tostring()
71+
buf = PIL.Image.frombuffer('RGBA', size, buf, 'raw', rawmode, 0, 1)
72+
# Image.tobytes() is named tostring() in Pillow 1.x and PIL
73+
buf = (getattr(buf, 'tobytes', None) or buf.tostring)()
7374
# Now load the image as RGBA, undoing premultiplication
7475
return PIL.Image.frombuffer('RGBA', size, buf, 'raw', 'RGBa', 0, 1)
7576

0 commit comments

Comments
 (0)