The toRgb() method is used to convert any type of the specified color representation to it’s RGB (Red Green Blue) representation.
Syntax:
toRgb()
Parameters: This method does not accept any parameter.
Return Value: This method returns color representation in RGB format.
Example 1:
HTML
<!DOCTYPE html> < html >
< head >
<!-- Adding the FabricJS library -->
< script src =
</ script >
</ head >
< body >
< script type = "text/javascript" >
// Calling the toRgb() function over
// the specified color values
console.log(new fabric.Color("hsl(0, 100%, 50%)").toRgb());
console.log(new fabric.Color("hsla(10, 40%, 53%, 0.6)").toRgb());
</ script >
</ body >
</ html >
|
Output:
rgb(255,0,0) rgb(183,103,87)
Example 2:
HTML
<!DOCTYPE html> < html >
< head >
<!-- Adding the FabricJS library -->
< script src =
</ script >
</ head >
< body >
< script type = "text/javascript" >
// Initializing some color values in different color format
var A = "hex(fff00f)";
var B = "hsl(12, 13%, 25%)";
// Calling the toRgb() function over
// the above specified color values
console.log(new fabric.Color(A).toRgb());
console.log(new fabric.Color(B).toRgb());
</ script >
</ body >
</ html >
|
Output:
rgb(0,0,0) rgb(72,59,55)