how to implement eraser in fabric js
var width = $('#image').width();
var height = $('#image').height();
var canvas = new fabric.Canvas('kv_mark', { selection: false , width: width, height: height });
var mark="";
var i=0;
var linex1=;
var linex2=;
var liney1=;
var liney2=;
var rightx=;
var righty=;
var wrongx=;
var wrongy=;
$('.mark-button').click(function(){
// alert('here');
mark = $(this).data('value');
if(mark=='right'){
img = "img/tick-green.png";
}
if(mark=='wrong'){
img = "img/wrong.png";
}
if(mark==""){alert('please select a tool');}
});
var line, isDown;
canvas.on('mouse:down', function(o){
if(mark=='line'){
isDown = true;
var pointer = canvas.getPointer(o.e);
var points = [ pointer.x, pointer.y, pointer.x, pointer.y ];
x1=pointer.x;
y1=pointer.y;
linex1.push(x1);
liney1.push(y1);
line = new fabric.Line(points, {
strokeWidth: 1 ,
fill: 'red',
stroke: 'red',
originX: 'center',
originY: 'center'
});
canvas.add(line);
}
});
canvas.on('mouse:move', function(o){
if(mark=='line'){
if (!isDown) return;
var pointer = canvas.getPointer(o.e);
line.set({ x2: pointer.x, y2: pointer.y });
canvas.renderAll();
// console.log(pointer);
}
});
canvas.on('mouse:up', function(o){
var pointer = canvas.getPointer(o.e);
x2=pointer.x;
y2=pointer.y;
linex2.push(x2);
liney2.push(y2);
if(mark=='line'){isDown = false;}
});
canvas.on('mouse:dblclick', function(o){
if(mark=='wrong' || mark=='right'){
var pointer = canvas.getPointer(o.e);
var x = pointer.x;
var y = pointer.y;
if(mark=='wrong'){
wrongx.push(x);
wrongy.push(y);
}
if(mark=='right'){
rightx.push(x);
righty.push(y);
}
$("#container").append('<img class="mark" src="http://localhost:9000/'+img+'" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:3;width:20px;height:20">');
//
// // $("#kv_mark").append('<img class="mark" src="{{ asset('wrong.png')}}" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:2;width:20px;height:20">');
i++;}
});
$('#container').on("click",".mark",function(e){
$(this).remove();
});
$('#kv_mark').on("click",".mark",function(e){
$(this).remove();
});
$("#kv_mark").dblclick(function(e){
a[i] = (e.pageX - this.offsetLeft)-17;
b[i] = (e.pageY - this.offsetTop)-17;
// console.log(a);
// console.log(b);
}) .correction-block{
width:100%;
position: relative;
}
.correction-block img{
width:100%;
}
.canvas-body{
position:relative;
/*top:0;
left:0;
height:100%;
width:100%;*/
}
.correction-block .canvas-container{
position: absolute!important;
top:0;
left:0;
width:100%!important;
height:100%!important;
border:1px solid #333;
}
.correction-block canvas{
position: absolute;
top:0;
left:0;
width:100%!important;
height:100%!important;
}
.relative{
position: relative;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.3/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" class="relative">
<div class="correction-block">
<img src="{{ asset('img/scanned1.jpeg') }}" alt="" id="image">
<canvas id="kv_mark"> </canvas>
</div>
</div>I implemented fabric js to draw over an image I don't how to erase on it I tried something but it is not erasing it is just adding white so my image is not showing there can anyone suggest how to add an eraser to fabric the way that it won't affect the image behind that canvas or any other approach to my problem
javascript html5-canvas fabricjs
add a comment |
var width = $('#image').width();
var height = $('#image').height();
var canvas = new fabric.Canvas('kv_mark', { selection: false , width: width, height: height });
var mark="";
var i=0;
var linex1=;
var linex2=;
var liney1=;
var liney2=;
var rightx=;
var righty=;
var wrongx=;
var wrongy=;
$('.mark-button').click(function(){
// alert('here');
mark = $(this).data('value');
if(mark=='right'){
img = "img/tick-green.png";
}
if(mark=='wrong'){
img = "img/wrong.png";
}
if(mark==""){alert('please select a tool');}
});
var line, isDown;
canvas.on('mouse:down', function(o){
if(mark=='line'){
isDown = true;
var pointer = canvas.getPointer(o.e);
var points = [ pointer.x, pointer.y, pointer.x, pointer.y ];
x1=pointer.x;
y1=pointer.y;
linex1.push(x1);
liney1.push(y1);
line = new fabric.Line(points, {
strokeWidth: 1 ,
fill: 'red',
stroke: 'red',
originX: 'center',
originY: 'center'
});
canvas.add(line);
}
});
canvas.on('mouse:move', function(o){
if(mark=='line'){
if (!isDown) return;
var pointer = canvas.getPointer(o.e);
line.set({ x2: pointer.x, y2: pointer.y });
canvas.renderAll();
// console.log(pointer);
}
});
canvas.on('mouse:up', function(o){
var pointer = canvas.getPointer(o.e);
x2=pointer.x;
y2=pointer.y;
linex2.push(x2);
liney2.push(y2);
if(mark=='line'){isDown = false;}
});
canvas.on('mouse:dblclick', function(o){
if(mark=='wrong' || mark=='right'){
var pointer = canvas.getPointer(o.e);
var x = pointer.x;
var y = pointer.y;
if(mark=='wrong'){
wrongx.push(x);
wrongy.push(y);
}
if(mark=='right'){
rightx.push(x);
righty.push(y);
}
$("#container").append('<img class="mark" src="http://localhost:9000/'+img+'" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:3;width:20px;height:20">');
//
// // $("#kv_mark").append('<img class="mark" src="{{ asset('wrong.png')}}" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:2;width:20px;height:20">');
i++;}
});
$('#container').on("click",".mark",function(e){
$(this).remove();
});
$('#kv_mark').on("click",".mark",function(e){
$(this).remove();
});
$("#kv_mark").dblclick(function(e){
a[i] = (e.pageX - this.offsetLeft)-17;
b[i] = (e.pageY - this.offsetTop)-17;
// console.log(a);
// console.log(b);
}) .correction-block{
width:100%;
position: relative;
}
.correction-block img{
width:100%;
}
.canvas-body{
position:relative;
/*top:0;
left:0;
height:100%;
width:100%;*/
}
.correction-block .canvas-container{
position: absolute!important;
top:0;
left:0;
width:100%!important;
height:100%!important;
border:1px solid #333;
}
.correction-block canvas{
position: absolute;
top:0;
left:0;
width:100%!important;
height:100%!important;
}
.relative{
position: relative;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.3/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" class="relative">
<div class="correction-block">
<img src="{{ asset('img/scanned1.jpeg') }}" alt="" id="image">
<canvas id="kv_mark"> </canvas>
</div>
</div>I implemented fabric js to draw over an image I don't how to erase on it I tried something but it is not erasing it is just adding white so my image is not showing there can anyone suggest how to add an eraser to fabric the way that it won't affect the image behind that canvas or any other approach to my problem
javascript html5-canvas fabricjs
can please add your code to jsfiddle? it is easy for others to provide solution.
– varit05
Nov 20 '18 at 6:05
add a comment |
var width = $('#image').width();
var height = $('#image').height();
var canvas = new fabric.Canvas('kv_mark', { selection: false , width: width, height: height });
var mark="";
var i=0;
var linex1=;
var linex2=;
var liney1=;
var liney2=;
var rightx=;
var righty=;
var wrongx=;
var wrongy=;
$('.mark-button').click(function(){
// alert('here');
mark = $(this).data('value');
if(mark=='right'){
img = "img/tick-green.png";
}
if(mark=='wrong'){
img = "img/wrong.png";
}
if(mark==""){alert('please select a tool');}
});
var line, isDown;
canvas.on('mouse:down', function(o){
if(mark=='line'){
isDown = true;
var pointer = canvas.getPointer(o.e);
var points = [ pointer.x, pointer.y, pointer.x, pointer.y ];
x1=pointer.x;
y1=pointer.y;
linex1.push(x1);
liney1.push(y1);
line = new fabric.Line(points, {
strokeWidth: 1 ,
fill: 'red',
stroke: 'red',
originX: 'center',
originY: 'center'
});
canvas.add(line);
}
});
canvas.on('mouse:move', function(o){
if(mark=='line'){
if (!isDown) return;
var pointer = canvas.getPointer(o.e);
line.set({ x2: pointer.x, y2: pointer.y });
canvas.renderAll();
// console.log(pointer);
}
});
canvas.on('mouse:up', function(o){
var pointer = canvas.getPointer(o.e);
x2=pointer.x;
y2=pointer.y;
linex2.push(x2);
liney2.push(y2);
if(mark=='line'){isDown = false;}
});
canvas.on('mouse:dblclick', function(o){
if(mark=='wrong' || mark=='right'){
var pointer = canvas.getPointer(o.e);
var x = pointer.x;
var y = pointer.y;
if(mark=='wrong'){
wrongx.push(x);
wrongy.push(y);
}
if(mark=='right'){
rightx.push(x);
righty.push(y);
}
$("#container").append('<img class="mark" src="http://localhost:9000/'+img+'" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:3;width:20px;height:20">');
//
// // $("#kv_mark").append('<img class="mark" src="{{ asset('wrong.png')}}" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:2;width:20px;height:20">');
i++;}
});
$('#container').on("click",".mark",function(e){
$(this).remove();
});
$('#kv_mark').on("click",".mark",function(e){
$(this).remove();
});
$("#kv_mark").dblclick(function(e){
a[i] = (e.pageX - this.offsetLeft)-17;
b[i] = (e.pageY - this.offsetTop)-17;
// console.log(a);
// console.log(b);
}) .correction-block{
width:100%;
position: relative;
}
.correction-block img{
width:100%;
}
.canvas-body{
position:relative;
/*top:0;
left:0;
height:100%;
width:100%;*/
}
.correction-block .canvas-container{
position: absolute!important;
top:0;
left:0;
width:100%!important;
height:100%!important;
border:1px solid #333;
}
.correction-block canvas{
position: absolute;
top:0;
left:0;
width:100%!important;
height:100%!important;
}
.relative{
position: relative;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.3/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" class="relative">
<div class="correction-block">
<img src="{{ asset('img/scanned1.jpeg') }}" alt="" id="image">
<canvas id="kv_mark"> </canvas>
</div>
</div>I implemented fabric js to draw over an image I don't how to erase on it I tried something but it is not erasing it is just adding white so my image is not showing there can anyone suggest how to add an eraser to fabric the way that it won't affect the image behind that canvas or any other approach to my problem
javascript html5-canvas fabricjs
var width = $('#image').width();
var height = $('#image').height();
var canvas = new fabric.Canvas('kv_mark', { selection: false , width: width, height: height });
var mark="";
var i=0;
var linex1=;
var linex2=;
var liney1=;
var liney2=;
var rightx=;
var righty=;
var wrongx=;
var wrongy=;
$('.mark-button').click(function(){
// alert('here');
mark = $(this).data('value');
if(mark=='right'){
img = "img/tick-green.png";
}
if(mark=='wrong'){
img = "img/wrong.png";
}
if(mark==""){alert('please select a tool');}
});
var line, isDown;
canvas.on('mouse:down', function(o){
if(mark=='line'){
isDown = true;
var pointer = canvas.getPointer(o.e);
var points = [ pointer.x, pointer.y, pointer.x, pointer.y ];
x1=pointer.x;
y1=pointer.y;
linex1.push(x1);
liney1.push(y1);
line = new fabric.Line(points, {
strokeWidth: 1 ,
fill: 'red',
stroke: 'red',
originX: 'center',
originY: 'center'
});
canvas.add(line);
}
});
canvas.on('mouse:move', function(o){
if(mark=='line'){
if (!isDown) return;
var pointer = canvas.getPointer(o.e);
line.set({ x2: pointer.x, y2: pointer.y });
canvas.renderAll();
// console.log(pointer);
}
});
canvas.on('mouse:up', function(o){
var pointer = canvas.getPointer(o.e);
x2=pointer.x;
y2=pointer.y;
linex2.push(x2);
liney2.push(y2);
if(mark=='line'){isDown = false;}
});
canvas.on('mouse:dblclick', function(o){
if(mark=='wrong' || mark=='right'){
var pointer = canvas.getPointer(o.e);
var x = pointer.x;
var y = pointer.y;
if(mark=='wrong'){
wrongx.push(x);
wrongy.push(y);
}
if(mark=='right'){
rightx.push(x);
righty.push(y);
}
$("#container").append('<img class="mark" src="http://localhost:9000/'+img+'" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:3;width:20px;height:20">');
//
// // $("#kv_mark").append('<img class="mark" src="{{ asset('wrong.png')}}" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:2;width:20px;height:20">');
i++;}
});
$('#container').on("click",".mark",function(e){
$(this).remove();
});
$('#kv_mark').on("click",".mark",function(e){
$(this).remove();
});
$("#kv_mark").dblclick(function(e){
a[i] = (e.pageX - this.offsetLeft)-17;
b[i] = (e.pageY - this.offsetTop)-17;
// console.log(a);
// console.log(b);
}) .correction-block{
width:100%;
position: relative;
}
.correction-block img{
width:100%;
}
.canvas-body{
position:relative;
/*top:0;
left:0;
height:100%;
width:100%;*/
}
.correction-block .canvas-container{
position: absolute!important;
top:0;
left:0;
width:100%!important;
height:100%!important;
border:1px solid #333;
}
.correction-block canvas{
position: absolute;
top:0;
left:0;
width:100%!important;
height:100%!important;
}
.relative{
position: relative;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.3/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" class="relative">
<div class="correction-block">
<img src="{{ asset('img/scanned1.jpeg') }}" alt="" id="image">
<canvas id="kv_mark"> </canvas>
</div>
</div>I implemented fabric js to draw over an image I don't how to erase on it I tried something but it is not erasing it is just adding white so my image is not showing there can anyone suggest how to add an eraser to fabric the way that it won't affect the image behind that canvas or any other approach to my problem
var width = $('#image').width();
var height = $('#image').height();
var canvas = new fabric.Canvas('kv_mark', { selection: false , width: width, height: height });
var mark="";
var i=0;
var linex1=;
var linex2=;
var liney1=;
var liney2=;
var rightx=;
var righty=;
var wrongx=;
var wrongy=;
$('.mark-button').click(function(){
// alert('here');
mark = $(this).data('value');
if(mark=='right'){
img = "img/tick-green.png";
}
if(mark=='wrong'){
img = "img/wrong.png";
}
if(mark==""){alert('please select a tool');}
});
var line, isDown;
canvas.on('mouse:down', function(o){
if(mark=='line'){
isDown = true;
var pointer = canvas.getPointer(o.e);
var points = [ pointer.x, pointer.y, pointer.x, pointer.y ];
x1=pointer.x;
y1=pointer.y;
linex1.push(x1);
liney1.push(y1);
line = new fabric.Line(points, {
strokeWidth: 1 ,
fill: 'red',
stroke: 'red',
originX: 'center',
originY: 'center'
});
canvas.add(line);
}
});
canvas.on('mouse:move', function(o){
if(mark=='line'){
if (!isDown) return;
var pointer = canvas.getPointer(o.e);
line.set({ x2: pointer.x, y2: pointer.y });
canvas.renderAll();
// console.log(pointer);
}
});
canvas.on('mouse:up', function(o){
var pointer = canvas.getPointer(o.e);
x2=pointer.x;
y2=pointer.y;
linex2.push(x2);
liney2.push(y2);
if(mark=='line'){isDown = false;}
});
canvas.on('mouse:dblclick', function(o){
if(mark=='wrong' || mark=='right'){
var pointer = canvas.getPointer(o.e);
var x = pointer.x;
var y = pointer.y;
if(mark=='wrong'){
wrongx.push(x);
wrongy.push(y);
}
if(mark=='right'){
rightx.push(x);
righty.push(y);
}
$("#container").append('<img class="mark" src="http://localhost:9000/'+img+'" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:3;width:20px;height:20">');
//
// // $("#kv_mark").append('<img class="mark" src="{{ asset('wrong.png')}}" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:2;width:20px;height:20">');
i++;}
});
$('#container').on("click",".mark",function(e){
$(this).remove();
});
$('#kv_mark').on("click",".mark",function(e){
$(this).remove();
});
$("#kv_mark").dblclick(function(e){
a[i] = (e.pageX - this.offsetLeft)-17;
b[i] = (e.pageY - this.offsetTop)-17;
// console.log(a);
// console.log(b);
}) .correction-block{
width:100%;
position: relative;
}
.correction-block img{
width:100%;
}
.canvas-body{
position:relative;
/*top:0;
left:0;
height:100%;
width:100%;*/
}
.correction-block .canvas-container{
position: absolute!important;
top:0;
left:0;
width:100%!important;
height:100%!important;
border:1px solid #333;
}
.correction-block canvas{
position: absolute;
top:0;
left:0;
width:100%!important;
height:100%!important;
}
.relative{
position: relative;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.3/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" class="relative">
<div class="correction-block">
<img src="{{ asset('img/scanned1.jpeg') }}" alt="" id="image">
<canvas id="kv_mark"> </canvas>
</div>
</div> var width = $('#image').width();
var height = $('#image').height();
var canvas = new fabric.Canvas('kv_mark', { selection: false , width: width, height: height });
var mark="";
var i=0;
var linex1=;
var linex2=;
var liney1=;
var liney2=;
var rightx=;
var righty=;
var wrongx=;
var wrongy=;
$('.mark-button').click(function(){
// alert('here');
mark = $(this).data('value');
if(mark=='right'){
img = "img/tick-green.png";
}
if(mark=='wrong'){
img = "img/wrong.png";
}
if(mark==""){alert('please select a tool');}
});
var line, isDown;
canvas.on('mouse:down', function(o){
if(mark=='line'){
isDown = true;
var pointer = canvas.getPointer(o.e);
var points = [ pointer.x, pointer.y, pointer.x, pointer.y ];
x1=pointer.x;
y1=pointer.y;
linex1.push(x1);
liney1.push(y1);
line = new fabric.Line(points, {
strokeWidth: 1 ,
fill: 'red',
stroke: 'red',
originX: 'center',
originY: 'center'
});
canvas.add(line);
}
});
canvas.on('mouse:move', function(o){
if(mark=='line'){
if (!isDown) return;
var pointer = canvas.getPointer(o.e);
line.set({ x2: pointer.x, y2: pointer.y });
canvas.renderAll();
// console.log(pointer);
}
});
canvas.on('mouse:up', function(o){
var pointer = canvas.getPointer(o.e);
x2=pointer.x;
y2=pointer.y;
linex2.push(x2);
liney2.push(y2);
if(mark=='line'){isDown = false;}
});
canvas.on('mouse:dblclick', function(o){
if(mark=='wrong' || mark=='right'){
var pointer = canvas.getPointer(o.e);
var x = pointer.x;
var y = pointer.y;
if(mark=='wrong'){
wrongx.push(x);
wrongy.push(y);
}
if(mark=='right'){
rightx.push(x);
righty.push(y);
}
$("#container").append('<img class="mark" src="http://localhost:9000/'+img+'" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:3;width:20px;height:20">');
//
// // $("#kv_mark").append('<img class="mark" src="{{ asset('wrong.png')}}" id="'+x+'_'+y+'" style="position:absolute;left:'+x+'px; top:'+y+'px; z-index:2;width:20px;height:20">');
i++;}
});
$('#container').on("click",".mark",function(e){
$(this).remove();
});
$('#kv_mark').on("click",".mark",function(e){
$(this).remove();
});
$("#kv_mark").dblclick(function(e){
a[i] = (e.pageX - this.offsetLeft)-17;
b[i] = (e.pageY - this.offsetTop)-17;
// console.log(a);
// console.log(b);
}) .correction-block{
width:100%;
position: relative;
}
.correction-block img{
width:100%;
}
.canvas-body{
position:relative;
/*top:0;
left:0;
height:100%;
width:100%;*/
}
.correction-block .canvas-container{
position: absolute!important;
top:0;
left:0;
width:100%!important;
height:100%!important;
border:1px solid #333;
}
.correction-block canvas{
position: absolute;
top:0;
left:0;
width:100%!important;
height:100%!important;
}
.relative{
position: relative;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.3/fabric.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" class="relative">
<div class="correction-block">
<img src="{{ asset('img/scanned1.jpeg') }}" alt="" id="image">
<canvas id="kv_mark"> </canvas>
</div>
</div>javascript html5-canvas fabricjs
javascript html5-canvas fabricjs
edited Nov 20 '18 at 6:08
kritarth
asked Nov 20 '18 at 5:53
kritarthkritarth
62
62
can please add your code to jsfiddle? it is easy for others to provide solution.
– varit05
Nov 20 '18 at 6:05
add a comment |
can please add your code to jsfiddle? it is easy for others to provide solution.
– varit05
Nov 20 '18 at 6:05
can please add your code to jsfiddle? it is easy for others to provide solution.
– varit05
Nov 20 '18 at 6:05
can please add your code to jsfiddle? it is easy for others to provide solution.
– varit05
Nov 20 '18 at 6:05
add a comment |
1 Answer
1
active
oldest
votes
It depends what kind of eraser are you talking about. In case of you'd like to create an object with the eraser characteristic (i.e. a circle or a rect) you just have to add to it the property globalCompositeOperation = 'destination-out'.
If you want a freeDrawingBrush eraser, feel free to ask; at this moment this is not a feature in Fabric (version: '2.4.4') and you should hack the library to do it.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387010%2fhow-to-implement-eraser-in-fabric-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It depends what kind of eraser are you talking about. In case of you'd like to create an object with the eraser characteristic (i.e. a circle or a rect) you just have to add to it the property globalCompositeOperation = 'destination-out'.
If you want a freeDrawingBrush eraser, feel free to ask; at this moment this is not a feature in Fabric (version: '2.4.4') and you should hack the library to do it.
add a comment |
It depends what kind of eraser are you talking about. In case of you'd like to create an object with the eraser characteristic (i.e. a circle or a rect) you just have to add to it the property globalCompositeOperation = 'destination-out'.
If you want a freeDrawingBrush eraser, feel free to ask; at this moment this is not a feature in Fabric (version: '2.4.4') and you should hack the library to do it.
add a comment |
It depends what kind of eraser are you talking about. In case of you'd like to create an object with the eraser characteristic (i.e. a circle or a rect) you just have to add to it the property globalCompositeOperation = 'destination-out'.
If you want a freeDrawingBrush eraser, feel free to ask; at this moment this is not a feature in Fabric (version: '2.4.4') and you should hack the library to do it.
It depends what kind of eraser are you talking about. In case of you'd like to create an object with the eraser characteristic (i.e. a circle or a rect) you just have to add to it the property globalCompositeOperation = 'destination-out'.
If you want a freeDrawingBrush eraser, feel free to ask; at this moment this is not a feature in Fabric (version: '2.4.4') and you should hack the library to do it.
answered Nov 25 '18 at 17:05
ZappescuZappescu
1,0991724
1,0991724
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387010%2fhow-to-implement-eraser-in-fabric-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown

can please add your code to jsfiddle? it is easy for others to provide solution.
– varit05
Nov 20 '18 at 6:05