Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptFabric.js getSource() Method

Fabric.js getSource() Method

The getSource() method is used to get the source of the specified color value.

Syntax:

getSource()

Parameters: This method does not accept any parameters.

Return Value: This method returns the source of the specified color value. The returned source value will be in an array representation.

Example 1:

HTML




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


Output:

[255,0,0,1]
[0,0,0,1]

Example 2:

HTML




<!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)";
 var E = "rgba(10, 40, 13, 0.9)";
  
 // Calling the getSource() function over
 // the above specified color values
 console.log(new fabric.Color(A).getSource());
 console.log(new fabric.Color(B).getSource());
 console.log(new fabric.Color(C).getSource());
 console.log(new fabric.Color(D).getSource());
 console.log(new fabric.Color(E).getSource());
</script>
  
</body>
  
</html>


Output:

[0,0,0,1]
[72,59,55,1]
[46,24,20,0.6]
[10,40,13,1]
[10,40,13,0.9]

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

Most Popular

Recent Comments