Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i make fabric.js save the state/ position of each object in canvas and restore back for future editing?

What format can allow me to save my drawing on canvas in file (not in the image file), and allow me to restore back for future editing, means the file can remember all the position of the object add into canvas and allow me to edit it in the future?
MY WORK
this is my work for now, just need a save button...

like image 919
Blu Ycw Avatar asked Oct 28 '25 16:10

Blu Ycw


1 Answers

You can save it as JSON & restore back for future editing.

Sample Code:

var canvas = json = '';
json = canvas.toJSON();
canvas.loadFromJSON(json, CallBack, function(o, object) {
    canvas.setActiveObject(object);
});

function CallBack() {
    canvas.renderAll();
    canvas.calcOffset();
}
like image 103
Mullainathan Avatar answered Oct 31 '25 11:10

Mullainathan