Fabric.js sourceFromHex() Method
Last Updated :
03 Feb, 2021
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" >
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" >
var Purple = "800080" ;
var Lime = "00FF00" ;
var Yellow = "FFFF00" ;
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]
Share your thoughts in the comments
Please Login to comment...