parseCSSColor

Parses a CSS color string, and gives back a Color.

pure nothrow @nogc @safe
bool
parseCSSColor
(
const(char)[] cssColorString
,,
out string error
)

Parameters

cssColorString const(char)[]

A CSS string describing a color.

outColor Color

Output color.

error string

Error message. null on success.

Return Value

Type: bool

A specified Color, that keeps the intent of the user. This is not necessarily usable right away, and will typically need sRGB conversion. In other words, colors stay in their colorspace of definition.

Examples

import colors;

// all HTML named colors
parseCSSColor("black", color, error);

// hex colors including alpha versions
parseCSSColor("#fe85dc", color, error);

// alpha                    
parseCSSColor("rgba(64, 255, 128, 0.24)", color, error);   

// percentage, floating-point
parseCSSColor("rgb(9e-1, 50%, 128)", color, error);

// hsv colors
parseCSSColor("hsl(120deg, 25%, 75%)", color, error);

// gray colors
parseCSSColor("gray(0.5)", color, error);

// strips whitespace
parseCSSColor(" rgb ( 245 , 112 , 74 )  ", color, error);

See Also

Meta