i try to "translate" this into fabricjs code, but i do something wrong. Is there a way to use globalCompositeOperation in fabricjs?
https://stackoverflow.com/questions/28545747/fill-image-with-texture-pattern
What i am doing wrong?
var canvas = this.__canvas = new fabric.Canvas('c');
fabric.Object.prototype.transparentCorners = false;
var padding = 0;
fabric.Image.fromURL('https://i.imgur.com/8WqH9v4.png', function(img) {
img.scaleToWidth(100);
var patternSourceCanvas = new fabric.StaticCanvas();
patternSourceCanvas.add(img);
patternSourceCanvas.renderAll();
var pattern = new fabric.Pattern({
source: function() {
patternSourceCanvas.setDimensions({
width: img.getScaledWidth() + padding,
height: img.getScaledHeight() + padding
});
patternSourceCanvas.renderAll();
return patternSourceCanvas.getElement();
},
repeat: 'no-repeat'
});
fabric.Image.fromURL('https://i.imgur.com/8WqH9v4.png', function(img) {
fill: pattern
});
});
})();```
Aucun commentaire:
Enregistrer un commentaire