In FabricJs, using the canvas.getActiveObject()
function, you can return the value of the currently active object.
I would like to know if there is any way to clone this object and add it to the canvas, with the same proportions and modifications.
Example:
var canvas = new fabric.Canvas('canvas', {preserveObjectStacking: true});
document.querySelector('#adicionar-objeto').addEventListener('click', function () {
fabric.Image.fromURL(url, function (image) {
image.scale(0.3);
image.opacity = .7;
canvas.add(image);
canvas.centerObject(image);
});
})
document.querySelector('#clonar-objeto').addEventListener('click', function () {
var obj = canvas.getActiveObject();
// Quero clonar esse objeto aqui e adicioná-lo ao canvas
})