Open In App

Fabric.js fromHsl() Method

The fromHsl() method is used to return a new color object for the specified color in HSL(Hue-Saturation-Lightness) format.

Syntax:



fromHsl(color)

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

Return Value: This method returns a new color object in the format of “RGBA(Red-Green-Blue-Alpha)” for the specified color in HSL format.



Example 1:




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
  <script type="text/javascript">
  
   // Calling the fromHsl() function over
   // the specified color value in HSL format
   console.log(fabric.Color.fromHsl("hsl(0, 100%, 50%)")); 
  </script>
</body>
  
</html>

Output:

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

Example 2:




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
  <script type="text/javascript">
  
   // Initializing some color values in HSL format
   var Green = "hsl(120, 100%, 50%)";
   var Blue = "hsl(240, 100%, 50%)";
  
   // Calling the fromHsl() function over
   // the above specified color values
   console.log(fabric.Color.fromHsl(Green)); 
   console.log(fabric.Color.fromHsl(Blue)); 
  </script>
</body>
  
</html>

Output:

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

Article Tags :