Pregunta

I have a canvas on one page that is built using fabricjs can i send that canvas to another page so that it retains all its objects as it is with all their properties and attributes to be same aswell.

¿Fue útil?

Solución

Sure you can, just export your canvas to JSON

var canvas = new fabric.Canvas('c');
data = JSON.stringify(canvas)

Now you can send that data using a post request or store it in a database or whatever you want.

canvas.loadFromJSON(data, canvas.renderAll.bind(canvas));

Example: http://jsfiddle.net/P9cEf/3/

The example uses two canvases one page, but the concept is the same.

Edit: To download the image client side

var canvas1 = document.getElementById("c");
var image = canvas1.toDataURL("image/png").replace("image/png", "image/octet-stream");
window.location.href = image;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top