[英]Text mask (destination-out) in fabric.js
What is the correct way to add text with fabric.js with a destination-out
fill mode? 用带有
destination-out
填充模式的fabric.js添加文本的正确方法是什么? I am trying to apply a text mask over a background image. 我正在尝试在背景图像上应用文本蒙版。
This is my simple approach so far. 到目前为止,这是我的简单方法。 I haven't added the BG yet, but would still expect the red mask to be knocked out:
我尚未添加BG,但仍然希望删除红色蒙版:
<canvas id="logo" width="600" height="250"></canvas>
$(document).ready(function(){
var canvas = new fabric.Canvas('logo');
canvas.backgroundColor="green";
var mask = new fabric.Rect({
left: 0,
top: 0,
width: 600,
height: 200,
fill :'red',
});
canvas.add(mask);
var text = new fabric.Text("TEST TEXT", {
fontSize: 120,
fontFamily: 'Arial',
fill: 'white',
stroke: "black",
fillRule: 'destination-out'
});
canvas.add(text);
});
Is this what you are looking for? 这是你想要的?
$(document).ready(function(){
var canvas = new fabric.Canvas('logo');
canvas.backgroundColor="green";
var mask = new fabric.Rect({
left: 0,
top: 0,
width: 600,
height: 200,
fill: 'blue'
});
canvas.add(mask);
var text = new fabric.Text("TEST TEXT", {
fontSize: 120,
fontFamily: 'Arial',
stroke: "black",
fill: 'none',
fillRule: 'destination-out'
});
canvas.add(text);
});
http://jsfiddle.net/disinfor/3x8bs/3/ http://jsfiddle.net/disinfor/3x8bs/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.