I want to set a fill to my rectangle in Fabric.js like this:
myRect.fill = new fabric.Pattern({
source: myImg //myImg was loaded previously in another
//fabric.util.loadImage block
});
My image is being loaded correctly before this code block is run. I've looked up the demos for patterns at Fabric.js website. There the pattern is set within a fabric.util.loadImage
block.
So the following code works fine for me:
fabric.util.loadImage('myImg.png', function(img) {
myRect.fill = new fabric.Pattern({
source: img
});
});
I want to understand why I can't set the source afterwards without using fabric.util.loadImage
. Is there an option with setting the fill using an already loaded image?