parseHTMLColor

Parses a HTML color string, and gives back a RGBA color.

  1. bool parseHTMLColor(const(char)[] htmlColorString, RGBA color, string error)
    nothrow @nogc @safe
    bool
    parseHTMLColor
    (
    const(char)[] htmlColorString
    ,,
    out string error
    )
  2. RGBA parseHTMLColor(const(char)[] htmlColorString)

Parameters

htmlColorString const(char)[]

A CSS string describing a color.

Return Value

Type: bool

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

Examples

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

See Also

Meta