Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f47001

Browse files
committed
Fix exception with Pillow 3
Image.fromstring was removed in Pillow 3.0. Also added missing numpy import.
1 parent 0bbff96 commit 7f47001

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/pylab_examples/agg_buffer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
convert it to an array and pass it to Pillow for rendering.
55
"""
66

7+
import numpy as np
8+
79
import matplotlib.pyplot as plt
810
from matplotlib.backends.backend_agg import FigureCanvasAgg
911

@@ -28,7 +30,10 @@
2830
X = np.fromstring(s, np.uint8)
2931
X.shape = h, w, 3
3032

31-
im = Image.fromstring("RGB", (w, h), s)
33+
try:
34+
im = Image.fromstring("RGB", (w, h), s)
35+
except Exception:
36+
im = Image.frombytes("RGB", (w, h), s)
3237

3338
# Uncomment this line to display the image using ImageMagick's
3439
# `display` tool.

0 commit comments

Comments
 (0)