Я хотел бы сохранить настроенный класс Fabric.Image как JSON, а затем восстановить его с помощью loadFromJSON.
Я посмотрел следующий вопрос Fabric.js - как сохранить холст насервер с пользовательскими атрибутами Но, похоже, что часть "fromObject" не работает.
Это происходит, когда вы нажимаете кнопку "Клик" на следующей веб-странице.https://onoderayuuki.github.io/tana_motif/index.html
[подкласс]
fabric.customMotif = fabric.util.createClass(fabric.Image, {
type: 'customMotif',
borderColor: '#19310B',
cornerColor: '#19310B',
cornerSize: 20,
initialize: function(src, options) {
this.callSuper('initialize', options);
options && this.set('name', options.name);
this.image = new Image();
this.top = options.top;
this.left = options.left;
this.image.src = src;
this.image.onload = (function() {
this.width = this.image.width;
this.height = this.image.height;
this.loaded = true;
this.setCoords();
this.fire('image:loaded');
}).bind(this);
},
toObject: function(options) {
return fabric.util.object.extend(this.callSuper('toObject'), {
});
},
_render: function(ctx) {
if (this.loaded) {
ctx.drawImage(this.image, -this.width / 2, -this.height / 2);
}
}
});
fabric.customMotif.fromObject = function(object, callback) {
fabric.util.loadImage(object.src, function(img) {
callback && callback(new fabric.customMotif(img, object));
});
};
[JSON]
canvasState = JSON.stringify(canvas);
canvas.loadFromJSON(canvasState);
спасибо.