Wednesday, July 3, 2024
HomeLanguagesJavascriptFabric.js sourceFromRgb() Method

Fabric.js sourceFromRgb() Method

The sourceFromRgb() method is used to return an array representation of color for the specified color values in RGB (Red Green Blue) or RGBA (Red Green Blue Alpha) format.

Syntax:

sourceFromRgb(color)

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

  • color: This parameter holds the specified color values in RGB or RGBA format.

Return Value: This method returns an array representation of values in RGBA (Red Green Blue and Alpha) format of the color for the specified color values in RGB or RGBA format.

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Calling the sourceFromRgb() function over
 // the color values in RGB and RGBA format
 console.log(fabric.Color.sourceFromRgb("rgb(13, 50, 77)"));
 console.log(fabric.Color.sourceFromRgb("rgba(200, 255, 252, 0.6)"));
</script>
  
</body>
  
</html>


Output:

[13,50,77,1]
[200,255,252,0.6]

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 RGB format
 var A = "rgb(0, 12, 50)";
 var B = "rgb(254, 200, 110)";
   
 // Initializing some color values in RGBA format
 var C = "rgba(5, 10, 50, 0.9)";
 var D = "rgba(12, 0, 150, 0.2)";
  
 // Calling the sourceFromRgb() function over
 // the above color values
 console.log(fabric.Color.sourceFromRgb(A));
 console.log(fabric.Color.sourceFromRgb(B));
 console.log(fabric.Color.sourceFromRgb(C));
 console.log(fabric.Color.sourceFromRgb(D));
</script>
  
</body>
  
</html>


Output:

[0,12,50,1]
[254,200,110,1]
[5,10,50,0.9]
[12,0,150,0.2]

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!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments