Immutable object representing a CSS color with the abilty to format as hex, rgba and X11 strings.
// Construct with R,G,B,A values. Alpha may be ommited and will default to 1
$color = new Color(0, 100, 200);
$color = new Color(0, 100, 200, 0.5);
// Create Color object from string
$color = Color::fromRgba('0,0,0,0');
$color = Color::fromRgb('0,0,0');
$color = Color::fromHex('000000');
$color = Color::fromShortHex('F00');
$color = Color::fromX11('rebeccapurple');
$color = Color::fromHsla('180, 0%, 85%, 1');
$color = Color::fromHsl('0, 100%, 10%');
// Get strings for different formats
$color = new Color(255, 255, 255, 1);
$color->toHex(); // #ffffff
$color->toRgba(); // rgba(255,255,255,1)
$color->toX11(); // white
// If a color can't be translated, it will be an empty string
$color = new Color(0, 0, 0, 0.5);
$color->toHex(); // ''
$color->toRgba(); // rgba(255,255,255,0.5)
$color->toX11(); // ''
- Create a toHsla() method