Skip to content

Commit

Permalink
Merge pull request #162 from meduz/moviepy3
Browse files Browse the repository at this point in the history
fix to work with python3
  • Loading branch information
Zulko committed Mar 17, 2016
2 parents d1dd63c + 2620677 commit d4c9c37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions moviepy/video/io/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ def PIL_to_npimage(im):

def mplfig_to_npimage(fig):
""" Converts a matplotlib figure to a RGB frame after updating the canvas"""
fig.canvas.draw() # update/draw the elements
w,h = fig.canvas.get_width_height()
buf = fig.canvas.tostring_rgb()
image= +np.fromstring(buf,dtype=np.uint8)
# only the Agg backend now supports the tostring_rgb function
from matplotlib.backends.backend_agg import FigureCanvasAgg
canvas = FigureCanvasAgg(fig)
canvas.draw() # update/draw the elements

# get the width and the height to resize the matrix
l,b,w,h = canvas.figure.bbox.bounds
w, h = int(w), int(h)

# exports the canvas to a string buffer and then to a numpy nd.array
buf = canvas.tostring_rgb()
image= np.fromstring(buf,dtype=np.uint8)
return image.reshape(h,w,3)


2 changes: 1 addition & 1 deletion moviepy/video/io/html_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def html_embed(clip, filetype=None, maxduration=60, rd_kwargs=None,
"but note that embedding large videos may take all the memory away !")

with open(filename, "rb") as f:
data= b64encode(f.read())
data= b64encode(f.read()).decode("utf-8")

template = templates[filetype]

Expand Down

0 comments on commit d4c9c37

Please sign in to comment.