Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect changes on canvas in fabricJS?

Is there any options to detect changes on fabricJS? I use following program to save my canvas. Then when save it again, I have to detect whether there are any changes on canvas before going to save it again. How to do this?

            var printImg  = canvas.toDataURL({
                format: 'png',
                multiplier: multi,
                left: (canvas.width - maskWidth)/2,
                height: maskOriHeight/multi,
                width: maskOriWidth/multi
            });
like image 659
isuru Avatar asked Oct 19 '22 07:10

isuru


1 Answers

I'm using following code to compare objects.

var oldJSON = JSON.stringify(canvas.toDatalessJSON(['id']));
var newJSON = JSON.stringify(canvas.toDatalessJSON(['id']));
if(newJSON === oldJSON) {
    console.log('Equal');
} else {
    console.log('Not Equal');
}
like image 131
Mullainathan Avatar answered Oct 20 '22 23:10

Mullainathan