diff --git a/moviepy/video/io/bindings.py b/moviepy/video/io/bindings.py index 74f1da5c9..6451c117f 100644 --- a/moviepy/video/io/bindings.py +++ b/moviepy/video/io/bindings.py @@ -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) diff --git a/moviepy/video/io/html_tools.py b/moviepy/video/io/html_tools.py index 00817a033..1c644c9d2 100644 --- a/moviepy/video/io/html_tools.py +++ b/moviepy/video/io/html_tools.py @@ -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]