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 to add some effects.
I can't make it work. My HTML is:
<form id="uploadImg" runat="server">
<input type="file" id="uploadedImg"/>
</form>
<canvas id="canvas"></canvas>
The JavaScript is the following:
var canvas = new fabric.Canvas('canvas');
canvas.setHeight(480);
canvas.setWidth(640);
$('#uploadedImg').change(function () {
var imgData = $(this).files[0];
fabric.util.loadImage(imgData, function(img) {
var oImg = new fabric.Image(img);
oImg.scale(0.2).set({
left: 100,
top: 100,
});
canvas.add(oImg);
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…