Open In App

Fabric.js fromSource() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The fromSource() method is used to return a new color object for the specified color in an array representation with values in RGBA (Red Green Blue and Alpha) format.

Syntax:

fromSource( source )

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

  • source: This parameter holds the specified array of values 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 an array.

Example 1:

Javascript




<!DOCTYPE html>
<html>
  
<head>
  
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        // Calling the fromSource() function
        // over the array of specified color
        // value in RGBA format
        console.log(fabric.Color
            .fromSource([200, 100, 100, 0.5]));
    </script>
</body>
  
</html>


Output:

{"_source":[200,100,100,0.5]}

Example 2:

Javascript




<!DOCTYPE html>
<html>
  
<head>
  
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        // Initializing some arrays of 
        // color values in RGBA format
        var Black = [0, 0, 0, 1.0];
        var Blue = [0, 0, 255, 0.5];
        var Yellow = [255, 255, 0.9];
  
        // Calling the fromSource() function over
        // the above array of specified color values
        console.log(fabric.Color.fromSource(Black));
        console.log(fabric.Color.fromSource(Blue));
        console.log(fabric.Color.fromSource(Yellow));
    </script>
</body>
  
</html>


Output:

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


Last Updated : 03 Feb, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads