Skip to content

Commit

Permalink
Fix exception with Pillow 3
Browse files Browse the repository at this point in the history
Image.fromstring was removed in Pillow 3.0.
Also added missing numpy import.
  • Loading branch information
cgohlke committed Oct 3, 2015
1 parent 0bbff96 commit 7f47001
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/pylab_examples/agg_buffer.py
Expand Up @@ -4,6 +4,8 @@
convert it to an array and pass it to Pillow for rendering.
"""

import numpy as np

import matplotlib.pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg

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

im = Image.fromstring("RGB", (w, h), s)
try:
im = Image.fromstring("RGB", (w, h), s)
except Exception:
im = Image.frombytes("RGB", (w, h), s)

# Uncomment this line to display the image using ImageMagick's
# `display` tool.
Expand Down

0 comments on commit 7f47001

Please sign in to comment.