I am currently working on importing png or svg files onto a canvas using the fabric.js library and an input file button. The code below works only if the image is in the root folder. I know that I don't have access to the file path, so I tried creating an element out of the file. There is no error in the console but nothing shows in the canvas. Is there a way to do make the importation work or is there a different library that could help me do this? I am using fabric.js in order to be able to scale and move the images within the canvas.
function upload(){
var canvas = new fabric.Canvas('canvas');
var file = document.getElementById('file').files[0].name;
fabric.Image.fromURL(file, function(img) {
canvas.add(img);
})
}
Yes!
There is a way to import an image / svg file using FabricJS, and that is as follows ...