Thursday, August 28, 2025
HomeLanguagesJavascriptFabric.js sourceFromHex() Method

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, 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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32236 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6609 POSTS0 COMMENTS
Nicole Veronica
11779 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11828 POSTS0 COMMENTS
Shaida Kate Naidoo
6719 POSTS0 COMMENTS
Ted Musemwa
7002 POSTS0 COMMENTS
Thapelo Manthata
6678 POSTS0 COMMENTS
Umr Jansen
6690 POSTS0 COMMENTS