Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to work with python3 #162

Merged
merged 5 commits into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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