Fabric.js sourceFromHex() Method

The sourceFromHex() method is used to return an array representation of color for the specified color values in HEX (hexadecimal) format.

Syntax:

sourceFromHex( color )

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

  • color: This parameter holds the specified color values in HEX 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 HEX (hexadecimal) format.

Example 1:

Javascript




<!DOCTYPE html>
<html>
  
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        // Calling the sourceFromHex() function over
        // the color value in HEX format
        console.log(fabric.Color.sourceFromHex("FF00FF"));
    </script>
</body>
  
</html>


Output:

[255, 0, 255, 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 HEX format
        var Purple = "800080";
        var Lime = "00FF00";
        var Yellow = "FFFF00";
  
        // Calling the sourceFromHex() function over
        // the above color values
        console.log(fabric.Color.sourceFromHex(Purple));
        console.log(fabric.Color.sourceFromHex(Lime));
        console.log(fabric.Color.sourceFromHex(Yellow));
    </script>
</body>
  
</html>


Output:

[128,0,128,1]
[0,255,0,1]
[255,255,0,1]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button