PHP code example of matthieumastadenis / couleur

1. Go to this page and download the library: Download matthieumastadenis/couleur library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matthieumastadenis / couleur example snippets







use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\ColorSpace;

50 ], ColorSpace::Hsl);
echo $css1; // Prints 'red'

// Convert to RGB:
$rgb1 = $css1->toRgb();

// Stringify:
echo $rgb1;                                          // Prints 'rgb(100% 0% 0%)'
echo $rgb1->stringify();                             // Prints 'rgb(100% 0% 0%)'
echo $rgb1->stringify(legacy : false, alpha : true); // Prints 'rgb(100% 0% 0% / 100%)'
echo $rgb1->stringify(legacy : true);                // Prints 'rgb(255,0,0)'
echo $rgb1->stringify(legacy : true, alpha : true);  // Prints 'rgba(255,0,0,1)'

// Create a variant color:
$rgb2 = $rgb1->change('-35', '+20', 60);
echo $rgb2->stringify(legacy : true); // Prints 'rgb(220,20,60)';

// Convert to CSS:
$css2 = $rgb2->toCss();
echo $css2; // Prints 'crimson'

// Convert to Lch:
$lch = $css2->toLch();
echo $lch->stringify(alpha : true); // Prints 'lch(47.878646049% 79.619059282 26.464486652deg / 100%)'

// Convert to P3:
$p3 = $lch->toP3();
echo $p3; // Prints 'color(display-p3 0.791710722 0.191507424 0.257366748)'




use matthieumastadenis\couleur\colors\Rgb;
use matthieumastadenis\couleur\colors\Hsl;

nstance (with 50% opacity):
$hex = new HexRgb('FF', '00', '00', '80');

// Create a new colors\Hsl instance (with 50% opacity):
$hsl = new Hsl(0, 100, 50, 50);

// Create a new colors\Rgb instance (with 50% opacity):
$rgb = new Rgb(255, 0, 0, 127.5);




use matthieumastadenis\couleur\ColorFactory;

ity):
$rgb1 = ColorFactory::newRgb('rgba(255,0,0,.5)');

// Returns a new colors\Lab instance:
$lab1 = ColorFactory::newLab('lab(54.29%,80.80,69.89,1)');

// Using a string value formatted with modern CSS syntax works as well:
$rgb2 = ColorFactory::newRgb('rgb(100% 0% 0% / 50%)');
$lab2 = ColorFactory::newLab('lab(54.29% 80.80 69.89 / 100%)');

// Using an array as a value also works:
$rgb3 = ColorFactory::newRgb([ 255, 0, 0, 127.5 ]);
$lab3 = ColorFactory::newLab([ 54.29, 80.80, 69.89, 100 ]);




use matthieumastadenis\couleur\ColorFactory;

ut:
$rgb = ColorFactory::newRgb('red');

// Returns a new colors\Css instance from a HSL input:
$css = ColorFactory::newCss('hsl(0deg,100%,50%)');

// Returns a new colors\XyzD65 instance from a Lab input:
$xyzD65 = ColorFactory::newXyzD65('lab(54.29% 80.80 69.89 / 100%)');




use matthieumastadenis\couleur\ColorFactory;

    $rgb = ColorFactory::newRgb('not valid');
}
catch (\Exception $e) {
    die($e); // Unknown color space
}




use matthieumastadenis\couleur\ColorFactory;

    $rgb = ColorFactory::newRgb('rgb(255,0)');
}
catch (\Exception $e) {
    die($e); // Color value "blue" is missing
}




use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\ColorSpace;

ColorFactory::newRgb([ 0, 100, 50 ]);
\var_dump($rgb1->coordinates()); // [ 0, 100, 50, 255 ]

// With the $from parameter, we can ensure that the input value will be treated like we want
// The following line creates a new colors\Rgb instance from an HSL input:
$rgb2 = ColorFactory::newRgb([ 0, 100, 50 ], 'hsl');
\var_dump($rgb2->coordinates()); // [ 255, 0, 0, 255 ]

// Same result, but with usage of the ColorSpace enum:
$rgb3 = ColorFactory::newRgb([ 0, 100, 50 ], ColorSpace::Hsl);
\var_dump($rgb3->coordinates()); // [ 255, 0, 0, 255 ]




use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\ColorSpace;

rgb(255,0,0)');

// Returns a new colors\HexRgb instance (space guessed automatically):
$hex = ColorFactory::new('#ff0000');

// Returns a new colors\Css instance (space guessed automatically):
$css = ColorFactory::new('red');

// Returns a new colors\Css instance from an RGB value:
$css = ColorFactory::new('rgb(255,0,0)', 'css');

// Same result but using the ColorSpace enum:
$css = ColorFactory::new('rgb(255,0,0)', ColorSpace::Css);

// Returns a new colors\Lch instance (using the ColorSpace enum):
$lch = ColorFactory::new([ 54.29, 106.84, 40.86 ], ColorSpace::Lch);

// Returns a new colors\OkLab instance from an RGB value (using the ColorSpace enum):
$okLab = ColorFactory::new([ 255, 0, 0 ], ColorSpace::OkLab, ColorSpace::Rgb);




use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\ColorSpace;

= $rgb->toCss();

// Converting to a new colors\XyzD50 instance:
$xyzD50 = $css->toXyzD50();

// Converting to a new colors\OkLch instance (using the to() method):
$okLch = $xyzD50->to(ColorSpace::OkLch);




use matthieumastadenis\couleur\ColorFactory;

= $rgb->toCss();

// Prints 'red':
echo $css;




use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\ColorSpace;

s 'rgb(100% 0% 0% / 100%)' ($alpha parameter):
echo $rgb->stringify(null, true);

// Prints 'rgba(255,0,0,1)' (using $legacy and $alpha parameters):
echo $rgb->stringify(true, true);

$lch = ColorFactory::newLch([ 54.2905429, 106.837191, 40.8576688 ], ColorSpace::Lch);

// Prints 'lch(54.29% 106.84 40.86deg)' Using the $precision parameter:
echo $lch->stringify(precision : 2);




use matthieumastadenis\couleur\ColorFactory;

 [ 'FF', '00', '00', 'FF' ]:
$values = $hex->coordinates();




use matthieumastadenis\couleur\ColorFactory;

nts 255:
echo $rgb->red;

$hsl = ColorFactory::newHsl([ 0, 100, 50 ]);

// Prints 50:
echo $hsl->lightness;




use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\ColorSpace;

0% 50% / 100%)

// Redefining coordinates:
$hsl2 = $hsl1->change(hue : 180, opacity : 80);
echo $hsl2; // hsl(180deg 100% 50% / 80%)

// Add, subtract, multiply, divide coordinates:
$hsl3 = $hsl2->change('+20', '-10', '*1.5', '/2');
echo $hsl3; // hsl(200deg 90% 75% / 40%)

// Reduce coordinates by modulus:
$hsl4 = $hsl3->change(opacity : '%6');
echo $hsl4; // hsl(200deg 90% 75% / 4%)

// Calculate the percentage of coordinates:
$hsl5 = $hsl4->change('50%');
echo $hsl5; // hsl(100deg 90% 75% / 4%)

// Add, subtract, multiply, divide coordinates by a percentage:
$hsl6 = $hsl5->change('+50%', '-50%', '/10%', '*200%');
echo $hsl6; // hsl(150deg 45% 10% / 32%)

// Reduce coordinates by a percentage modulus:
$hsl7 = $hsl6->change(saturation : '%20%');
echo $hsl7; // hsl(150deg 0% 10% / 32%)




use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\ColorSpace;

rovide hexadecimal numbers:
$hex2 = $hex1->change('80', 'AA', 'BB', 'AA');
echo $hex2; // #80AABBAA

// When adding or subtracting coordinates, provide hexadecimal numbers:
$hex3 = $hex2->change('+8', '-11');
echo $hex3; // #89BA (88 99 BB AA)

// When multiplying, dividing or reducing coordinates by modulo, provide decimal numbers:
$hex4 = $hex3->change(null, '*1.5', '/2', '%3');
echo $hex4; // #88E65E02 (88 dechex(153*1.5) dechex(187/2) dechex(170%3))

// When using percentages, provide decimal numbers:
$hex5 = $hex4->change('20%');
echo $hex5; // #1BE65E02 (dechex(136*20/100) E6 5E 02)

// When using percentages with addition, substraction, multiplication or division, provide decimal numbers:
$hex6 = $hex5->change('+50%', '-20%', '/2%', '*200%');
echo $hex6; // #29B83208 (dechex(27+(27*50/100)) dechex(230-(230*20/100)) dechex(94/(84*2/100)) dechex(2*(2*200/100)))

// When using percentages with modulo, provide decimal numbers:
$hex7 = $hex6->change(green : '%4%');
echo $hex7; // #29023208 (29 dechex(184%(184*4/100)) 32 08)




use matthieumastadenis\couleur\ColorFactory;
use matthieumastadenis\couleur\CssColor;

lor::purple);
echo $css2; // purple

$css2 = $css1->change(CssColor::purple);
echo $css2; // purple

$css3 = $css2->change('hotpink');
echo $css3; // hotpink

// Throws an UnsupportedCssColor Exception:
$css4 = $css3->change('invalid');





use matthieumastadenis\couleur\utils\css;
use matthieumastadenis\couleur\utils\rgb;
use matthieumastadenis\couleur\utils\lch;

ll of the following return [ 255, 0, 0, 255 ]:
$rgb1 = rgb\clean([ '100%', '0%', '0%', '100%' ]);
$rgb2 = rgb\clean([ 255, 0, 0, '100%' ]);
$rgb3 = rgb\clean('rgb(255,0,0)');
$rgb4 = rgb\clean('rgba(255,0,0,1)');
$rgb5 = rgb\clean('rgb(100% 0 0 / 100%)');
$rgb6 = rgb\clean('color(rgb 100% 0 0 / 100%)');

// All of the following return [ 54.2905429, 106.837191, 40.8576688, 100 ]:
$lch1 = lch\clean([ 54.2905429, 106.837191, 40.8576688 ]);
$lch2 = lch\clean([ '54.2905429%', '106.837191', '40.8576688deg' ]);
$lch3 = lch\clean('lch(54.2905429%,106.837191,40.8576688deg)');
$lch4 = lch\clean('lch(54.2905429% 106.837191 40.8576688deg / 100%)');
$lch5 = lch\clean('color(lch 54.2905429% 106.837191 40.8576688deg)');
$lch6 = lch\clean('color(lch 54.2905429% 106.837191 40.8576688deg / 100%)');




use matthieumastadenis\couleur\utils\rgb;
use matthieumastadenis\couleur\utils\lch;
use matthieumastadenis\couleur\ColorSpace;

('red', ColorSpace::Css);

// All of the following convert and clean from RGB to HSL,
// returning [ 0, 100, 50, 100 ]:
$hsl1 = hsl\from([ 255, 0, 0, 255 ]);
$hsl2 = hsl\from('rgb(100% 0% 0% / 100%)');
$hsl3 = hsl\from('rgba(255,0,0,1)', 'rgb');
$hsl4 = hsl\from('rgba(255,0,0,1)', ColorSpace::Rgb);




use matthieumastadenis\couleur\utils\hexRgb;
use matthieumastadenis\couleur\utils\rgb;
use matthieumastadenis\couleur\utils\xyzD65;

, '00', sharp : false);

// Prints '#F00' (using array destructuring on clean() result):
echo hexRgb\stringify(... hexRgb\clean('#FF0000'));

// Prints '#FF0000' (using $short parameter):
echo hexRgb\stringify('FF', '00', '00', short : false);

// Prints '#F00F' (using $alpha parameter):
echo hexRgb\stringify('FF', '00', '00', alpha : true);

// Prints '#FF0000FF' (using $alpha and $short parameters):
echo hexRgb\stringify('FF', '00', '00', alpha : true, short : false);

// Prints 'rgb(100% 0% 0%)':
echo rgb\stringify(255, 0, 0);

// Prints 'rgb(100% 0% 0%)' (using array destructuring on clean() result):
echo rgb\stringify(... rgb\clean('rgb(255,0,0,1)'));

// Prints 'rgb(100% 0% 0% / 100%)' (using $alpha parameter):
echo rgb\stringify(255, 0, 0, alpha : true);

// Prints 'rgb(255,0,0)' (using $legacy parameter):
echo rgb\stringify(255, 0, 0, legacy : true);

// Prints 'rgba(255,0,0,1)' (using $legacy and $alpha parameters):
echo rgb\stringify(255, 0, 0, legacy : true, alpha : true);

// Prints 'color(xyz-d65 0.412390799 0.212639006 0.019330819)':
echo xyzD65\stringify(0.412390799, 0.212639006, 0.019330819);

// Prints 'color(xyz-d65 0.412390799 0.212639006 0.019330819 / 100%)' (using $alpha parameter):
echo xyzD65\stringify(0.412390799, 0.212639006, 0.019330819, alpha : true);




use matthieumastadenis\couleur\utils\css;
use matthieumastadenis\couleur\utils\hexRgb;
use matthieumastadenis\couleur\utils\hsl;

e:
\var_dump(hexRgb\verify('f00'));
\var_dump(hexRgb\verify('f00f'));
\var_dump(hexRgb\verify('ff0000'));
\var_dump(hexRgb\verify('ff0000ff'));
\var_dump(hexRgb\verify('#f00'));
\var_dump(hexRgb\verify('#f00f'));
\var_dump(hexRgb\verify('#ff0000'));
\var_dump(hexRgb\verify('#ff0000ff'));

// Returns false:
\var_dump(hexRgb\verify('invalid'));

// The following also return false, because they eventually could be mistaken for RGB values:
\var_dump(hexRgb\verify([ 'ff', '00', '00' ]));
\var_dump(hexRgb\verify([ 'ff', '00', '00', 'ff' ]));

// All of the following return true:
\var_dump(hsl\verify('hsl(0,100,50)'));
\var_dump(hsl\verify('hsl(0deg,100%,50%)'));
\var_dump(hsl\verify('hsla(0,100,50,1)'));
\var_dump(hsl\verify('hsla(0deg,100%,50%,1)'));
\var_dump(hsl\verify('color(hsl,0,100,50,1)'));
\var_dump(hsl\verify('color(hsl,0deg,100%,50%,1)'));
\var_dump(hsl\verify('color(hsl 0 100 50 / 1)'));
\var_dump(hsl\verify('color(hsl 0deg 100% 50% / 1)'));

// All of the following return false:
\var_dump(hsl\verify('0,100,50'));
\var_dump(hsl\verify('hsl 0,100'));

// The following also return false, because they eventually could be mistaken for RGB values:
\var_dump(hexRgb\verify([ 0, 100, 50 ]));
\var_dump(hexRgb\verify([ '0deg', '100%', '50%' ]));




use matthieumastadenis\couleur\utils\css;
use matthieumastadenis\couleur\utils\rgb;
use matthieumastadenis\couleur\CssColor;

turns [  0.43606574282481, 0.22249319175624, 0.013923904500943, 1 ]
$xyzD50 = hsl\toXyzD50(... $hsl);




use matthieumastadenis\couleur\utils;

nknown'));

// Returns 7:
\var_dump(utils\constant('precision', 7));

// Creates the constant with a value of 3, then returns 3:
\var_dump(utils\constant('precision', 3, true));

// Now that the constant was created, always returns 3:
\var_dump(utils\constant('precision'));




use matthieumastadenis\couleur\utils;
use matthieumastadenis\couleur\ColorSpace;

e::Rgb:
$space = utils\findColorSpace('rgba(255,0,0,1)');

// Also returns ColorSpace::Rgb:
$space = utils\findColorSpace([ 255, 0, 0, 255 ]);

// Throws a UnknownColorSpace Exception:
$space = utils\findColorSpace('invalid');

// Returns ColorSpace::Rgb (using the $fallback parameter):
$space = utils\findColorSpace('invalid', ColorSpace::Rgb);

// Returns null (using the $throw parameter):
$space = utils\findColorSpace('invalid', throw : false);




use matthieumastadenis\couleur\utils;
use matthieumastadenis\couleur\ColorSpace;

,0,1)'));
\var_dump(utils\isColorString('rgb(100% 0% 0% / 100%)', 'rgb'));
\var_dump(utils\isColorString('rgba(255,0,0,1)', [ 'rgb', 'rgba' ]));
\var_dump(utils\isColorString('color(srgb 100% 0% 0% / 100%)', ColorSpace::Rgb));

// All of the following return false:
\var_dump(utils\isColorString('invalid'));
\var_dump(utils\isColorString('rgb 100%'));
\var_dump(utils\isColorString('255,0,0'));
\var_dump(utils\isColorString('rgba(255,0,0,1)', 'rgb'));
\var_dump(utils\isColorString('srgb(255,0,0,1)', [ 'rgb', 'rgba' ]));
\var_dump(utils\isColorString('myCustomRgb( 100% 0% 0% / 100%)', ColorSpace::Rgb));
\var_dump(utils\isColorString('color(myCustomRgb 100% 0% 0% / 100%)', ColorSpace::Rgb));




use matthieumastadenis\couleur\utils;
use matthieumastadenis\couleur\CssColor;

s [ 255, 0, 0, 1 ]:
$values = utils\parseColorValue('rgb(255,0,0,1)');

// Returns [ 255, 0, 0, 255 ] (using the $opacityFactor parameter):
$values = utils\parseColorValue('rgb(255,0,0,1)', 255);

// Returns [ '100%', '0%', '0%', '100%' ]:
$values = utils\parseColorValue('rgb(100% 0% 0% / 100%)');

// Returns [ CssColor::red ]
$values = utils\parseColorValue(CssColor::red);

// Returns [ 255, 0, 0, 255 ]:
$values = utils\parseColorValue([ 255, 0, 0, 255 ]);




use matthieumastadenis\couleur\utils;
use matthieumastadenis\couleur\ColorSpace;

arameter):
$css = utils\to('red', 'css');

// Returns [ 255, 0, 0, 255 ]:
// ([ CssColor::red ] is a valid CSS color so we can omit the $from parameter):
$rgb = utils\to($css, ColorSpace::Rgb);

// Returns [ 0, 100, 50, 100 ]:
// ([ 255, 0, 0, 255 ] is a valid RGB color so we can omit the $from parameter):
$hsl = utils\to($rgb, ColorSpace::Hsl);

// Returns [ 54.29054294697, 80.804920334624, 69.890988258963, 100 ]
// (the $from parameter avoids HSL array being interpreted as RGB):
$lab = utils\to($hsl, ColorSpace::Lab, ColorSpace::Hsl);

// Returns [ 54.29054294697, 106.83719104366, 40.857668782131, 100 ]
// (the $from parameter avoids Lab array being interpreted as RGB):
$lch = utils\to($lab, ColorSpace::Lch, ColorSpace::Lab);

// Returns [ 0.41239079028139, 0.21263903420017, 0.01933077971095, 100 ]
// (the $from parameter avoids Lch array being interpreted as RGB):
$xyzD65 = utils\to($lch, ColorSpace::XyzD65, ColorSpace::Lch);

// Returns [ 0.70226883304033, 0.27562276714962, 0.10344904551878, 1 ]
// (here we use a valid string input so we can omit the $from paramter):
$proPhoto = utils\to('color(xyz-d65 0.4124 0.2126 0.0193 / 100%)', ColorSpace::ProPhoto);




use matthieumastadenis\couleur\Constant;

);

// Always returns 0, which is the default value for the COULEUR_LEGACY constant:
Constant::LEGACY->value;

// Always returns 9, which is the default value for the COULEUR_PRECISION constant:
Constant::PRECISION->value;

// Returns the value of the COULEUR_LEGACY constant if defined, or 0 by default:
Constant::LEGACY->value();

// Returns the value of the COULEUR_PRECISION constant if defined, or 9 by default:
Constant::PRECISION->value();

// Returns the value of the COULEUR_LEGACY constant if defined, or 1 as fallback:
Constant::LEGACY->value(1);

// Returns the value of the COULEUR_PRECISION constant if defined, or 3 as fallback:
Constant::PRECISION->value(3);

// Returns the value of the COULEUR_LEGACY constant if defined, or define it with 1 as value then returns 1:
Constant::LEGACY->value(1, true);

// Returns the value of the COULEUR_PRECISION constant if defined, or define it with 3 as value then returns 3:
Constant::PRECISION->value(3, true);




use matthieumastadenis\couleur\ColorSpace;

s();




use matthieumastadenis\couleur\ColorSpace;
use matthieumastadenis\couleur\colors\Lch;
use matthieumastadenis\couleur\colors\LinP3;
use matthieumastadenis\couleur\colors\Rgb;





use matthieumastadenis\couleur\ColorSpace;

lAliases();

// Returns aliases of the HexRgb space:
ColorSpace::HexRgb->aliases();

// Returns ColorSpace::Rgb:
ColorSpace::fromAlias('rgb');
ColorSpace::fromAlias('srgb');
ColorSpace::fromAlias('RGBA');

// Returns ColorSpace::Lab:
ColorSpace::fromAlias('lab');
ColorSpace::fromAlias('cielab');
ColorSpace::fromAlias('CIE-LAB');




use matthieumastadenis\couleur\ColorSpace;
use matthieumastadenis\couleur\CssColor;

ack();

// Returns [ 255, 127.5, 0, 255 ]:
ColorSpace::Rgb->cleanCallback()('rgb(100%,50%,0)');

// Returns [ 'FF', '00', '00', 'FF' ]:
ColorSpace::HexRgb->cleanCallback()('#f00');

// Returns 'matthieumastadenis\couleur\utils\xyzD50\from':
ColorSpace::XyzD50->fromCallback();

// Returns [ 255, 0, 0, 255 ]:
ColorSpace::Rgb->fromCallback()('hsl(0deg,100%,50%)');

// Returns CssColor::red:
ColorSpace::Css->fromCallback()('#f00');

// Returns 'matthieumastadenis\couleur\utils\xyzD50\stringify':
ColorSpace::XyzD50->stringifyCallback();

// Returns 'rgb(100% 0% 0% / 50%):
ColorSpace::Rgb->stringifyCallback()(255, 0 , 0, 127.5);

// Returns '#F00':
ColorSpace::Css->stringifyCallback()(CssColor::red);

// Returns 'matthieumastadenis\couleur\utils\css\verify':
ColorSpace::Css->verifyCallback();

// Returns true:
ColorSpace::Rgb->verifyCallback()('rgb(100%,50%,0)');

// Returns false:
ColorSpace::HexRgb->verifyCallback()('#ff');




use matthieumastadenis\couleur\CssColor;

);

// Returns RGB coordinates for all supported CSS colors:
CssColor::allRgbCoordinates();

// Returns HexRgb coordinates for all supported CSS colors:
CssColor::allHexRgbCoordinates();

// Returns true (the 'red' color exists):
CssColor::exists('red');

// Returns [ 255, 0, 0 ]:
CssColor::red->toRgbCoordinates();

// Returns [ 'FF', '00', '00' ]:
CssColor::red->toHexRgbCoordinates();




use matthieumastadenis\couleur\CssColor;

d');

// Throws a UnsupportedCssColor Exception:
CssColor::fromCss('unknown');

// Returns CssColor::pink Exception:
CssColor::fromCss('unknown', CssColor::pink);

// Returns null:
CssColor::fromCss('unknown', null, false);




use matthieumastadenis\couleur\CssColor;

o #FA1111:
CssColor::fromHexRgb('FA', '11', '11');

// Throws a UnsupportedCssColor Exception:
CssColor::fromHexRgb('FA', '11', '11', false);

// Returns CssColor::pink:
CssColor::fromHexRgb('FA', '11', '11', false, CssColor::pink);

// Returns null:
CssColor::fromHexRgb('FA', '11', '11', false, null, false);

// Returns CssColor::red which is the closest to rgb(250,10,10):
CssColor::fromRgb(250, 10, 10);

// Throws a UnsupportedCssColor Exception:
CssColor::fromRgb(250, 10, 10, false);

// Returns CssColor::pink:
CssColor::fromRgb(250, 10, 10, false, CssColor::pink);

// Returns null:
CssColor::fromRgb(250, 10, 10, false, null, false);




use matthieumastadenis\couleur\CssColor;

g();

// Returns '#f00' (using the $uppercase parameter):
CssColor::red->toHexRgbString(uppercase : false);

// Returns 'F00' (using the $sharp parameter):
CssColor::red->toHexRgbString(sharp : false);

// Returns '#F00F' (using the $alpha parameter):
CssColor::red->toHexRgbString(true);

// Returns '#FF0000' (using the $short parameter):
CssColor::red->toHexRgbString(short : false);

// Returns '#FF0000FF' (using $alpha and $short parameters):
CssColor::red->toHexRgbString(true, false);

// Returns '#ff0000ff' (using $alpha, $short and $uppercase parameters):
CssColor::red->toHexRgbString(true, false, false);

// Returns 'ff0000ff' (using $alpha, $short, $uppercase and $sharp parameters):
CssColor::red->toHexRgbString(true, false, false, false);

// Returns 'rgb(100% 0% 0%)':
CssColor::red->toRgbString();

// Returns 'rgb(100% 0% 0% / 100%)' (using the $alpha parameter):
CssColor::red->toRgbString(alpha : true);

// Returns 'rgb(255,0,0)' (using the $legacy parameter):
CssColor::red->toRgbString(true);

// Returns 'rgba(255,0,0,1)' (using the $legacy and $alpha parameters):
CssColor::red->toRgbString(true, true);




use matthieumastadenis\couleur\CssColor;

:red->toCss();

// Returns a new colors\HexRgb instance:
CssColor::red->toHexRgb();

// Returns a new colors\Rgb instance:
CssColor::red->toRgb();