- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to make controlling corners of Text transparent using FabricJS?
In this tutorial, we are going to learn how to make the controlling corners of Text transparent using FabricJS.We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. The transparentCorners property allows us to make the controlling corners of Text object transparent.
Syntax
new fabric.Text(text: String ,{ transparentCorners: Boolean }: Object)
Parameters
text − This parameter accepts a String which is the text string that we want to display.
options (optional) − This parameter is an Object which provides additional customizations to our text. Using this parameter colour, cursor, stroke width and a lot of other properties can be changed related to the object of which transparentCorners is a property.
Options Keys
transparentCorners − This property accepts a Boolean value which allows us to render the controlling corners of an object as transparent. Its default value is true.
Example 1
Passing transparentCorners property as key with a ‘false’ value
Let’s see a code example to create a text object with controlling corners that are not transparent. To achieve this, we need to pass the transparentCorners property a false value.
<!DOCTYPE html> <html> <head> <!-- Adding the Fabric JS Library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> </head> <body> <h2>Passing transparentCorners property as key with a ‘false’ value</h2> <p>You can select the text object to see that the controlling corners are opaque</p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); // Initiate a text object var text = new fabric.Text("Add sample text here.", { left: 60, top: 70, fill: "violet", stroke: "blue", textAlign: "center", transparentCorners: false, }); // Add it to the canvas canvas.add(text); </script> </body> </html>
Example 2
Passing transparentCorners as key with a ‘true’ value
In this example, we are passing the transparentCorners property a true value. This will make sure that the controlling corners are rendered as transparent. Note, that this is also the default behaviour
<!DOCTYPE html> <html> <head> <!-- Adding the Fabric JS Library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> </head> <body> <h2>Passing transparentCorners as key with a ‘true’ value</h2> <p>You can select the text to see that the controlling corners are transparent</p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); // Initiate a text object var text = new fabric.Text("Add sample text here.", { left: 60, top: 70, fill: "violet", stroke: "blue", transparentCorners: true, }); // Add it to the canvas canvas.add(text); </script> </body> </html>
- Related Articles
- How to make the controlling corners of an Ellipse transparent using FabricJS?
- How to make the controlling corners of a Circle transparent using FabricJS?
- How to make the controlling corners of a Triangle transparent using FabricJS?
- How to make the controlling corners of a Rectangle transparent using FabricJS?
- How to make the controlling corners of a Textbox transparent using FabricJS?
- How to set the style of controlling corners of Text using FabricJS?
- How to set the dash pattern of controlling corners of Text using FabricJS?
- How to set the size of the controlling corners of Text using FabricJS?
- How to hide the controlling corners of an Ellipse using FabricJS?
- How to hide the controlling corners of a Circle using FabricJS?
- How to hide the controlling corners of a Triangle using FabricJS?
- How to hide the controlling corners of a Rectangle using FabricJS?
- How to set the color of controlling corners of Ellipse using FabricJS?
- How to set the style of controlling corners of Ellipse using FabricJS?
- How to set the colour of controlling corners of Textbox using FabricJS?
