How to upload an image to a canvas with Fabric.js?

后端 未结 3 566
轮回少年
轮回少年 2020-12-28 08:31

I want that to create a process where the users can upload their images and then edit them in the browser in a Canvas with Fabric.js using some buttons, which uses Fabric.js

3条回答
  •  鱼传尺愫
    2020-12-28 08:54

    document.getElementById('imgLoader').onchange = function handleImage(e) {
    var reader = new FileReader();
      reader.onload = function (event){
        var imgObj = new Image();
        imgObj.src = event.target.result;
        imgObj.onload = function () {
          var image = new fabric.Image(imgObj);
          image.set({
                angle: 0,
                padding: 10,
                cornersize:10,
                height:110,
                width:110,
          });
          canvas.centerObject(image);
          canvas.add(image);
          canvas.renderAll();
        }
      }
      reader.readAsDataURL(e.target.files[0]);
    }
    

提交回复
热议问题