Open In App

Fabric.js fromRgba() Method

Last Updated : 03 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The fromRgba() method is used to return a new color object for the specified color in RGBA(red green blue and alpha) format.

Syntax:

fromRgba(color)

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

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

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

Example 1:

Javascript




<!DOCTYPE html>
<html>
  
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        // Calling the fromRgba() function over the
        // above specified color value in RGBA format
        console.log(fabric.Color.fromRgba("rgb(0, 0, 128, 0.4)"));
    </script>
</body>
  
</html>


Output:

{"_source":[0,0,128,0.4]}

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 RGBA format
        var Black = "rgba(0, 0, 0, 1.0)";
        var Blue = "rgba(0, 0, 255, 0.5)";
        var Yellow = "rgba(255, 255, 0.9)";
  
        // Calling the fromRgba() function over
        // the above specified color values
        console.log(fabric.Color.fromRgba(Black));
        console.log(fabric.Color.fromRgba(Blue));
        console.log(fabric.Color.fromRgba(Yellow));
    </script>
</body>
  
</html>


Output:

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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads