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