HomeLanguagesJavascriptFabric.js fromRgb() Method

Fabric.js fromRgb() Method

The fromRgb() method is used to return a new color object for the specified color in RGB(red, green, and blue) format.

Syntax:

fromRgb(color)

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

  • color: This parameter holds the specified string color value in RGB format.

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

Example 1:

Javascript




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
  <script type="text/javascript">
  
   // Calling the fromRgb() function over
   // the specified color value in RGB format
   console.log(fabric.Color.fromRgb("rgb(255, 0, 0)")); 
   console.log(fabric.Color.fromRgb("rgb(10, 14, 20)")); 
  </script>
  
</body>
  
</html>


Output:

{"_source":[255,0,0,1]}
{"_source":[10,14,20,1]}

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 RGB format
   var Lime = "rgb(255, 0, 0)";
   var Blue = "rgb(0, 0, 255)";
   var Yellow = "rgb(255, 255, 0)";
  
   // Calling the fromRgb() function over
   // the above specified color values
   console.log(fabric.Color.fromRgb(Lime)); 
   console.log(fabric.Color.fromRgb(Blue)); 
   console.log(fabric.Color.fromRgb(Yellow)); 
  </script>
  
</body>
  
</html>


Output:

{"_source":[255,0,0,1]}
{"_source":[0,0,255,1]}
{"_source":[255,255,0,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
32712 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7086 POSTS0 COMMENTS
Nicole Veronica
12226 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12309 POSTS0 COMMENTS
Shaida Kate Naidoo
7202 POSTS0 COMMENTS
Ted Musemwa
7469 POSTS0 COMMENTS
Thapelo Manthata
7187 POSTS0 COMMENTS
Umr Jansen
7171 POSTS0 COMMENTS