parseHTMLColor

Parses a HTML color and gives back a RGBA triplet.

pure @safe
ubyte[4]
parseHTMLColor
(
const(char)[] htmlColorString
)

Parameters

htmlColorString
Type: const(char)[]

A CSS string describing a color.

Return Value

Type: ubyte[4]

A 32-bit RGBA color, with each component between 0 and 255.

Examples

1 import printed.htmlcolors;
2 parseHTMLColor("black");                      // all HTML named colors
3 parseHTMLColor("#fe85dc");                    // hex colors including alpha versions
4 parseHTMLColor("rgba(64, 255, 128, 0.24)");   // alpha
5 parseHTMLColor("rgb(9e-1, 50%, 128)");        // percentage, floating-point
6 parseHTMLColor("hsl(120deg, 25%, 75%)");      // hsv colors
7 parseHTMLColor("gray(0.5)");                  // gray colors
8 parseHTMLColor(" rgb ( 245 , 112 , 74 )  ");  // strips whitespace

See Also

Meta