Saturday, June 13, 2026
HomeLanguagesJavascriptFabric.js toBlackWhite() Method

Fabric.js toBlackWhite() Method

The toBlackWhite() method is used to convert any type of the specified color representation to it’s black and white representation.

Syntax:

toBlackWhite(threshold)

Parameters: This method accepts a parameter as mentioned above and described below:

  • threshold: This parameter holds the specified threshold value.

Return Value: This method returns color representation in it’s black and white representation.

Example 1:

Javascript




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Calling the toBlackWhite() function over 
 // the specified color values
 console.log(new fabric.Color("hsl(0, 100%, 50%)").toBlackWhite(0));
 console.log(new fabric.Color("hsla(10, 40%, 53%, 0.6)").toBlackWhite(1));
</script>
  
</body>
  
</html>


Output:

{"_source":[0,0,0,1]}
{"_source":[255,255,255,0.6]}

Example 2:

Javascript




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Initializing some color values in different color format
 var A = "hex(fff00f)";
 var B = "hsl(12, 13%, 25%)";
 var C = "hsla(10, 40%, 13%, 0.6)";
 var D = "rgb(10, 40, 13)";
  
 // Calling the toBlackWhite() function over 
 // the above specified color values
 console.log(new fabric.Color(A).toBlackWhite());
 console.log(new fabric.Color(B).toBlackWhite(0));
 console.log(new fabric.Color(C).toBlackWhite(1));
 console.log(new fabric.Color(D).toBlackWhite(2));
</script>
  
</body>
  
</html>


Output:

{"_source":[0,0,0,1]}
{"_source":[0,0,0,1]}
{"_source":[255,255,255,0.6]}
{"_source":[255,255,255,1]}
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS