{"id":25453086,"url":"https://github.com/atomicptr/color","last_synced_at":"2026-02-08T21:08:10.623Z","repository":{"id":276143369,"uuid":"928314822","full_name":"atomicptr/color","owner":"atomicptr","description":"Couleur is a modern PHP 8.1+ color library, intended to be compatible with CSS Color Module Level 4.","archived":false,"fork":false,"pushed_at":"2025-02-06T16:23:16.000Z","size":193,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-16T09:57:31.913Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atomicptr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-06T12:38:59.000Z","updated_at":"2025-02-06T16:23:19.000Z","dependencies_parsed_at":"2025-02-06T15:17:56.789Z","dependency_job_id":"b77ef294-8819-4003-aa0c-ccc2345522f2","html_url":"https://github.com/atomicptr/color","commit_stats":null,"previous_names":["atomicptr/color"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicptr%2Fcolor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicptr%2Fcolor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicptr%2Fcolor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicptr%2Fcolor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomicptr","download_url":"https://codeload.github.com/atomicptr/color/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239384745,"owners_count":19629509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-17T23:49:13.882Z","updated_at":"2026-02-08T21:08:10.590Z","avatar_url":"https://github.com/atomicptr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎨 Color: A modern PHP 8.3+ color library\n\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/atomicptr/color/blob/main/LICENSE)\n[![PHP Version](https://img.shields.io/packagist/php-v/atomicptr/color?style=flat)](https://packagist.org/packages/atomicptr/color)\n[![Last commit on main branch](https://img.shields.io/github/last-commit/atomicptr/color)](https://github.com/atomicptr/color)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/atomicptr/color)](https://packagist.org/packages/atomicptr/color)\n[![Total Packagist downloads](https://img.shields.io/packagist/dt/atomicptr/color)](https://packagist.org/packages/atomicptr/color)\n\n**Color** is a modern **PHP 8.3+ color library**, intended to be compatible with **[CSS Color Module Level 4](https://drafts.csswg.org/css-color-4)**, and inspired by **[Color.js](https://github.com/LeaVerou/color.js)** from [Lea Verou](https://github.com/LeaVerou) and [Chris Lilley](https://github.com/svgeesus).\n\nThis is a hard fork of [matthieumastadenis/couleur](https://github.com/matthieumastadenis/couleur)\n\nThe main goal of this package is to allow **color conversions** between multiple, old and new [🌈 Color Spaces](#-color-spaces), like the famous **LCH** which provides [many advantages for design purpose](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/).\n\n**Color** is made to be usable with an **[OOP](https://en.wikipedia.org/wiki/Object-oriented_programming)** approach as well as with a **[FP](https://en.wikipedia.org/wiki/Functional_programming)** approach:\n\n- If you prefer **OOP**, you can use [🏭 Immutable Objects and the `ColorFactory`](#-immutable-objects-and-the-colorfactory) ;\n- If you prefer **FP**, you can directly use the multiple [🧰 Pure Functions](#-pure-functions) ;\n\n## ⚙️ Installation\n\nUse the following command to add **Color** to your project with [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require atomicptr/color\n```\n\nDon't forget to include the [autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading) provided by Composer:\n\n```php\n\u003c?php\n\nrequire 'vendor/autoload.php';\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n## 🏁 Quick Start\n\nThe following is a quick *tl;dr* example of the simplest way to use **Color**, based on an OOP approach. For more detailed instructions, please read the [📚 Usage](#-usage) section.\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// Create a new colors\\Css instance from an HSL array:\n$css1 = ColorFactory::newCss([ 0, 100, 50 ], ColorSpace::Hsl);\necho $css1; // Prints 'red'\n\n// Convert to RGB:\n$rgb1 = $css1-\u003etoRgb();\n\n// Stringify:\necho $rgb1;                                          // Prints 'rgb(100% 0% 0%)'\necho $rgb1-\u003estringify();                             // Prints 'rgb(100% 0% 0%)'\necho $rgb1-\u003estringify(legacy : false, alpha : true); // Prints 'rgb(100% 0% 0% / 100%)'\necho $rgb1-\u003estringify(legacy : true);                // Prints 'rgb(255,0,0)'\necho $rgb1-\u003estringify(legacy : true, alpha : true);  // Prints 'rgba(255,0,0,1)'\n\n// Create a variant color:\n$rgb2 = $rgb1-\u003echange('-35', '+20', 60);\necho $rgb2-\u003estringify(legacy : true); // Prints 'rgb(220,20,60)';\n\n// Convert to CSS:\n$css2 = $rgb2-\u003etoCss();\necho $css2; // Prints 'crimson'\n\n// Convert to Lch:\n$lch = $css2-\u003etoLch();\necho $lch-\u003estringify(alpha : true); // Prints 'lch(47.878646049% 79.619059282 26.464486652deg / 100%)'\n\n// Convert to P3:\n$p3 = $lch-\u003etoP3();\necho $p3; // Prints 'color(display-p3 0.791710722 0.191507424 0.257366748)'\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n## 📚 Usage\n\n### 🏭 Immutable Objects and the `ColorFactory`\n\n#### Direct instanciation\n\n**Color** provides one **immutable class** for each supported [🌈 Color Space](#-color-spaces). You can of course instantiate these classes manually:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Colors\\Rgb;\nuse Atomicptr\\Color\\Colors\\Hsl;\n\nrequire 'vendor/autoload.php';\n\n// Create a new colors\\Css instance:\n$rgb = new Css('red');\n\n// Create a new colors\\HexRgb instance (with 50% opacity):\n$hex = new HexRgb('FF', '00', '00', '80');\n\n// Create a new colors\\Hsl instance (with 50% opacity):\n$hsl = new Hsl(0, 100, 50, 50);\n\n// Create a new colors\\Rgb instance (with 50% opacity):\n$rgb = new Rgb(255, 0, 0, 127.5);\n\n```\n\n\u003e **Note** :\n\u003e You may have noticed from the previous example that it implies passing *correctly formatted* values to each constructor.\n\u003e\n\u003e For example, the `Rgb` class expects to receive opacity expressed in the same magnitude than red, green and blue values, meaning *as a number between 0 and 255*. Same thing for the `HexRgb` class which expects only *hexadecimal strings* for each of the four parameters it takes (opacity included).\n\u003e\n\u003e Because of this, you may prefer to avoid instanciating these classes yourself. A simpler solution is to [use the ColorFactory](#using-the-colorfactory) like in the following examples. It will automatically handle *values conversion* for you.\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n#### Using the `ColorFactory`\n\nThe best and simplest way to create color objects is by using the `ColorFactory` **abstract class** which provides a specific **static method** for each supported [🌈 Color Space](#-color-spaces):\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\n\nrequire 'vendor/autoload.php';\n\n// Returns a new colors\\Rgb instance (with 50% opacity):\n$rgb1 = ColorFactory::newRgb('rgba(255,0,0,.5)');\n\n// Returns a new colors\\Lab instance:\n$lab1 = ColorFactory::newLab('lab(54.29%,80.80,69.89,1)');\n\n// Using a string value formatted with modern CSS syntax works as well:\n$rgb2 = ColorFactory::newRgb('rgb(100% 0% 0% / 50%)');\n$lab2 = ColorFactory::newLab('lab(54.29% 80.80 69.89 / 100%)');\n\n// Using an array as a value also works:\n$rgb3 = ColorFactory::newRgb([ 255, 0, 0, 127.5 ]);\n$lab3 = ColorFactory::newLab([ 54.29, 80.80, 69.89, 100 ]);\n\n```\n\nNote that by default these methods are **automatically guessing** the input syntax. This means it's possible to provide an input value in a different format than the expected output, and the **conversion** will happen automatically:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\n\nrequire 'vendor/autoload.php';\n\n// Returns a new colors\\Rgb instance from a CSS input:\n$rgb = ColorFactory::newRgb('red');\n\n// Returns a new colors\\Css instance from a HSL input:\n$css = ColorFactory::newCss('hsl(0deg,100%,50%)');\n\n// Returns a new colors\\XyzD65 instance from a Lab input:\n$xyzD65 = ColorFactory::newXyzD65('lab(54.29% 80.80 69.89 / 100%)');\n\n```\n\nIf you use an incorrectly formated value, a `UnknownColorSpace` **Exception** will be thrown:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\n\nrequire 'vendor/autoload.php';\n\ntry {\n    // Throws a UnknownColorSpace Exception:\n    $rgb = ColorFactory::newRgb('not valid');\n}\ncatch (\\Exception $e) {\n    die($e); // Unknown color space\n}\n\n```\n\nAlso if you use an incomplete value, a `MissingColorValue` **Exception** will be thrown:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\n\nrequire 'vendor/autoload.php';\n\ntry {\n    // Throws a MissingColorValue Exception:\n    $rgb = ColorFactory::newRgb('rgb(255,0)');\n}\ncatch (\\Exception $e) {\n    die($e); // Color value \"blue\" is missing\n}\n\n```\n\nBy using the `$from` parameter, you can specify the *input color space* with a *string alias* or with the [ColorSpace enum](#the-colorspace-enum). Like before, the value will automatically be converted from it to the targetted space.\n\nSpecifying this is particularly helpful when you're using an array as input, to be sure it will not be treated as RGB (which is the default for an array of numbers):\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// Without the $from parameter, array values are considered as RGB values by default:\n$rgb1 = ColorFactory::newRgb([ 0, 100, 50 ]);\n\\var_dump($rgb1-\u003ecoordinates()); // [ 0, 100, 50, 255 ]\n\n// With the $from parameter, we can ensure that the input value will be treated like we want\n// The following line creates a new colors\\Rgb instance from an HSL input:\n$rgb2 = ColorFactory::newRgb([ 0, 100, 50 ], 'hsl');\n\\var_dump($rgb2-\u003ecoordinates()); // [ 255, 0, 0, 255 ]\n\n// Same result, but with usage of the ColorSpace enum:\n$rgb3 = ColorFactory::newRgb([ 0, 100, 50 ], ColorSpace::Hsl);\n\\var_dump($rgb3-\u003ecoordinates()); // [ 255, 0, 0, 255 ]\n\n```\n\nYou can alternatively use the `new()` **static method**, which adds a `$to` parameter just after the input value. If this parameter is not specified, the *targetted color space* will automatically be determined according to the format of the value:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// Returns a new colors\\Rgb instance (space guessed automatically):\n$rgb = ColorFactory::new('rgb(255,0,0)');\n\n// Returns a new colors\\HexRgb instance (space guessed automatically):\n$hex = ColorFactory::new('#ff0000');\n\n// Returns a new colors\\Css instance (space guessed automatically):\n$css = ColorFactory::new('red');\n\n// Returns a new colors\\Css instance from an RGB value:\n$css = ColorFactory::new('rgb(255,0,0)', 'css');\n\n// Same result but using the ColorSpace enum:\n$css = ColorFactory::new('rgb(255,0,0)', ColorSpace::Css);\n\n// Returns a new colors\\Lch instance (using the ColorSpace enum):\n$lch = ColorFactory::new([ 54.29, 106.84, 40.86 ], ColorSpace::Lch);\n\n// Returns a new colors\\OkLab instance from an RGB value (using the ColorSpace enum):\n$okLab = ColorFactory::new([ 255, 0, 0 ], ColorSpace::OkLab, ColorSpace::Rgb);\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n#### Using immutable color objects\n\nOnce you have a color instance, you can easily convert it to another color space using one of its dedicated `to...()` methods, which will return a new object:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n$rgb = ColorFactory::newRgb([ 255, 0, 0 ]);\n\n// Converting to a new colors\\Css instance:\n$css = $rgb-\u003etoCss();\n\n// Converting to a new colors\\XyzD50 instance:\n$xyzD50 = $css-\u003etoXyzD50();\n\n// Converting to a new colors\\OkLch instance (using the to() method):\n$okLch = $xyzD50-\u003eto(ColorSpace::OkLch);\n\n```\n\nNote that **any color** can be converted to CSS with the `toCss()` method. It will automatically pick the *closest* CSS color:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\n\nrequire 'vendor/autoload.php';\n\n$rgb = ColorFactory::newRgb([ 250, 10, 10 ]);\n$css = $rgb-\u003etoCss();\n\n// Prints 'red':\necho $css;\n\n```\n\nAll color objects are directly **stringable**. They also provide a `stringify()` method which offers more possibilities:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n$rgb = ColorFactory::newRgb([ 255, 0, 0 ]);\n\n// Prints 'rgb(100% 0% 0%)':\necho $rgb;\n\n// Prints 'rgb(100% 0% 0% / 100%)' ($alpha parameter):\necho $rgb-\u003estringify(null, true);\n\n// Prints 'rgba(255,0,0,1)' (using $legacy and $alpha parameters):\necho $rgb-\u003estringify(true, true);\n\n$lch = ColorFactory::newLch([ 54.2905429, 106.837191, 40.8576688 ], ColorSpace::Lch);\n\n// Prints 'lch(54.29% 106.84 40.86deg)' Using the $precision parameter:\necho $lch-\u003estringify(precision : 2);\n\n```\n\nAll color objects also have a `coordinates()` method which returns an array:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\n\nrequire 'vendor/autoload.php';\n\n$hex = ColorFactory::newHexRgb('#F00');\n\n// Returns [ 'FF', '00', '00', 'FF' ]:\n$values = $hex-\u003ecoordinates();\n\n```\n\nYou can also directly access **readonly properties** from each color object:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\n\nrequire 'vendor/autoload.php';\n\n$rgb = ColorFactory::newRgb([ 255, 0, 0 ]);\n\n// Prints 255:\necho $rgb-\u003ered;\n\n$hsl = ColorFactory::newHsl([ 0, 100, 50 ]);\n\n// Prints 50:\necho $hsl-\u003elightness;\n\n```\n\nAll color objects have a `change()` method which always return a *new object* corresponding to a *variant* of the current color.\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n$hsl1 = ColorFactory::newHsl([ 0, 100, 50, 100 ], ColorSpace::Hsl);\necho $hsl1; // hsl(0deg 100% 50% / 100%)\n\n// Redefining coordinates:\n$hsl2 = $hsl1-\u003echange(hue : 180, opacity : 80);\necho $hsl2; // hsl(180deg 100% 50% / 80%)\n\n// Add, subtract, multiply, divide coordinates:\n$hsl3 = $hsl2-\u003echange('+20', '-10', '*1.5', '/2');\necho $hsl3; // hsl(200deg 90% 75% / 40%)\n\n// Reduce coordinates by modulus:\n$hsl4 = $hsl3-\u003echange(opacity : '%6');\necho $hsl4; // hsl(200deg 90% 75% / 4%)\n\n// Calculate the percentage of coordinates:\n$hsl5 = $hsl4-\u003echange('50%');\necho $hsl5; // hsl(100deg 90% 75% / 4%)\n\n// Add, subtract, multiply, divide coordinates by a percentage:\n$hsl6 = $hsl5-\u003echange('+50%', '-50%', '/10%', '*200%');\necho $hsl6; // hsl(150deg 45% 10% / 32%)\n\n// Reduce coordinates by a percentage modulus:\n$hsl7 = $hsl6-\u003echange(saturation : '%20%');\necho $hsl7; // hsl(150deg 0% 10% / 32%)\n\n```\n\n\u003e **Note**:\n\u003e The `change()` method of the `HexRgb` class behave differently depending on the operation you ask for :\n\u003e\n\u003e - For replacing a coordinate you have to provide an **hexadecimal value** ;\n\u003e - For additions and substractions you have to provide an **hexadecimal value** ;\n\u003e - For all other operactions you have to provide a **decimal value** ;\n\u003e\n\u003e Please observe the detailed demonstration in the next example:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n$hex1 = ColorFactory::newHexRgb('#F00');\necho $hex1; // #F00\n\n// When replacing coordinates, provide hexadecimal numbers:\n$hex2 = $hex1-\u003echange('80', 'AA', 'BB', 'AA');\necho $hex2; // #80AABBAA\n\n// When adding or subtracting coordinates, provide hexadecimal numbers:\n$hex3 = $hex2-\u003echange('+8', '-11');\necho $hex3; // #89BA (88 99 BB AA)\n\n// When multiplying, dividing or reducing coordinates by modulo, provide decimal numbers:\n$hex4 = $hex3-\u003echange(null, '*1.5', '/2', '%3');\necho $hex4; // #88E65E02 (88 dechex(153*1.5) dechex(187/2) dechex(170%3))\n\n// When using percentages, provide decimal numbers:\n$hex5 = $hex4-\u003echange('20%');\necho $hex5; // #1BE65E02 (dechex(136*20/100) E6 5E 02)\n\n// When using percentages with addition, substraction, multiplication or division, provide decimal numbers:\n$hex6 = $hex5-\u003echange('+50%', '-20%', '/2%', '*200%');\necho $hex6; // #29B83208 (dechex(27+(27*50/100)) dechex(230-(230*20/100)) dechex(94/(84*2/100)) dechex(2*(2*200/100)))\n\n// When using percentages with modulo, provide decimal numbers:\n$hex7 = $hex6-\u003echange(green : '%4%');\necho $hex7; // #29023208 (29 dechex(184%(184*4/100)) 32 08)\n\n```\n\n\u003e **Note**:\n\u003e The `change()` method of the `Css` class also behave differently: it only accepts a stringable color name or an instances of [the CssColor Enum](#the-csscolor-enum), which replace the color without variations.\n\u003e\n\u003e Please observe the next example:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorFactory;\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n$css1 = ColorFactory::newCss(CssColor::red);\necho $css1; // red\n\n$css2 = $css1-\u003echange(CssColor::purple);\necho $css2; // purple\n\n$css2 = $css1-\u003echange(CssColor::purple);\necho $css2; // purple\n\n$css3 = $css2-\u003echange('hotpink');\necho $css3; // hotpink\n\n// Throws an UnsupportedCssColor Exception:\n$css4 = $css3-\u003echange('invalid');\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n### 🧰 Pure Functions\n\nObjects in **Color** are all based on a collection of **pure functions** under the hood. These functions can be used directly if you don't want to use objects.\n\n\u003e **Note**:\n\u003e Choosing this *functional programming approach* is better in terms of performance, but can be a bit more tedious because you have to manipulate arrays of values instead of objects.\n\nThere are three main types of functions provided by **Color** : dedicated [Color Space Functions](#color-space-functions), dedicated [Conversion Functions](#conversion-functions), and [Generic Functions](#generic-functions):\n\n#### Color Space Functions\n\nEach supported [🌈 Color Space](#-color-spaces) has its own dedicated functions, accessible under the namespace `Atomicptr\\Color\\Utils\\[space]`. Those are the same for each color space: `clean()`, `from()`, `stringify()` and `verify()`.\n\n`clean()` functions are made to transform an input value in a correctly formated set of values, according to the corresponding color space. They all return an array, except for `css\\clean()` which directly returns an instance of the [the `CssColor` Enum](#the-csscolor-enum):\n\n```php\n\n\u003c?php\n\nuse Atomicptr\\Color\\Utils\\CSS;\nuse Atomicptr\\Color\\Utils\\RGB;\nuse Atomicptr\\Color\\Utils\\Lch;\n\nrequire 'vendor/autoload.php';\n\n// All of the following return ColorSpace::red:\n$css1 = css\\clean('red');\n$css2 = css\\clean(' red ');\n$css3 = css\\clean('RED');\n\n// All of the following return [ 255, 0, 0, 255 ]:\n$rgb1 = rgb\\clean([ '100%', '0%', '0%', '100%' ]);\n$rgb2 = rgb\\clean([ 255, 0, 0, '100%' ]);\n$rgb3 = rgb\\clean('rgb(255,0,0)');\n$rgb4 = rgb\\clean('rgba(255,0,0,1)');\n$rgb5 = rgb\\clean('rgb(100% 0 0 / 100%)');\n$rgb6 = rgb\\clean('color(rgb 100% 0 0 / 100%)');\n\n// All of the following return [ 54.2905429, 106.837191, 40.8576688, 100 ]:\n$lch1 = lch\\clean([ 54.2905429, 106.837191, 40.8576688 ]);\n$lch2 = lch\\clean([ '54.2905429%', '106.837191', '40.8576688deg' ]);\n$lch3 = lch\\clean('lch(54.2905429%,106.837191,40.8576688deg)');\n$lch4 = lch\\clean('lch(54.2905429% 106.837191 40.8576688deg / 100%)');\n$lch5 = lch\\clean('color(lch 54.2905429% 106.837191 40.8576688deg)');\n$lch6 = lch\\clean('color(lch 54.2905429% 106.837191 40.8576688deg / 100%)');\n\n```\n\n`from()` functions **convert** and **clean** an input value from the specified color space (with the `$from` parameter) to the color space corresponding to the used namespace. If no *input color space* is specified with the `$from` parameter, it will be automatically guessed from the format of the `$value`:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils\\RGB;\nuse Atomicptr\\Color\\Utils\\Lch;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// All of the following convert and clean from CSS to RGB,\n// returning [ 255, 0, 0, 255 ]:\n$rgb1 = rgb\\from('red');\n$rgb2 = rgb\\from('red', ColorSpace::Css);\n\n// All of the following convert and clean from RGB to HSL,\n// returning [ 0, 100, 50, 100 ]:\n$hsl1 = hsl\\from([ 255, 0, 0, 255 ]);\n$hsl2 = hsl\\from('rgb(100% 0% 0% / 100%)');\n$hsl3 = hsl\\from('rgba(255,0,0,1)', 'rgb');\n$hsl4 = hsl\\from('rgba(255,0,0,1)', ColorSpace::Rgb);\n\n```\n\n`stringify()` functions return a *color string* fully compatible with CSS syntax. Depending of each color space, these functions can have the following parameters:\n\n- `$sharp` : only for `HexRgb` colors, this can be used to include or not the hexadecimal sharp character (#) ;\n- `$short` : only for `HexRgb` colors, this can be used to force or prevent the shortening of the value (#f00 instead of #ff0000) ;\n- `$uppercase` : only for `HexRgb` colors, this can be used to force the conversion to uppercase or lowercase (by default the case is preserved) ;\n- `$alpha` : can be used to force  or prevent the inclusion of opacity (by default opacity is included only if it has a value other than 100%) ;\n- `$precision` : number of decimals used to round values (by defaut the [`COULEUR_PRECISION` constant](#the-constant-enum) is used) ;\n- `$legacy` : if true the color string will be formatted according to the traditional CSS syntax rather than the modern one (rgba(255,0,0,1) instead of rgb(100% 0% 0% / 100%)) ;\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils\\HexRGB;\nuse Atomicptr\\Color\\Utils\\RGB;\nuse Atomicptr\\Color\\Utils\\XyzD65;\n\nrequire 'vendor/autoload.php';\n\n// Prints '#F00':\necho hexRgb\\stringify('FF', '00', '00');\n\n// Prints 'FF0' (using the $sharp parameter):\necho hexRgb\\stringify('FF', '00', '00', sharp : false);\n\n// Prints '#F00' (using array destructuring on clean() result):\necho hexRgb\\stringify(... hexRgb\\clean('#FF0000'));\n\n// Prints '#FF0000' (using $short parameter):\necho hexRgb\\stringify('FF', '00', '00', short : false);\n\n// Prints '#F00F' (using $alpha parameter):\necho hexRgb\\stringify('FF', '00', '00', alpha : true);\n\n// Prints '#FF0000FF' (using $alpha and $short parameters):\necho hexRgb\\stringify('FF', '00', '00', alpha : true, short : false);\n\n// Prints 'rgb(100% 0% 0%)':\necho rgb\\stringify(255, 0, 0);\n\n// Prints 'rgb(100% 0% 0%)' (using array destructuring on clean() result):\necho rgb\\stringify(... rgb\\clean('rgb(255,0,0,1)'));\n\n// Prints 'rgb(100% 0% 0% / 100%)' (using $alpha parameter):\necho rgb\\stringify(255, 0, 0, alpha : true);\n\n// Prints 'rgb(255,0,0)' (using $legacy parameter):\necho rgb\\stringify(255, 0, 0, legacy : true);\n\n// Prints 'rgba(255,0,0,1)' (using $legacy and $alpha parameters):\necho rgb\\stringify(255, 0, 0, legacy : true, alpha : true);\n\n// Prints 'color(xyz-d65 0.412390799 0.212639006 0.019330819)':\necho xyzD65\\stringify(0.412390799, 0.212639006, 0.019330819);\n\n// Prints 'color(xyz-d65 0.412390799 0.212639006 0.019330819 / 100%)' (using $alpha parameter):\necho xyzD65\\stringify(0.412390799, 0.212639006, 0.019330819, alpha : true);\n\n```\n\n`verify()` functions simply return a **boolean** indicating if the input value matches the corresponding *color space*:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils\\CSS;\nuse Atomicptr\\Color\\Utils\\HexRGB;\nuse Atomicptr\\Color\\Utils\\HSL;\n\nrequire 'vendor/autoload.php';\n\n// Returns true:\n\\var_dump(css\\verify('red'));\n\n// Returns false:\n\\var_dump(css\\verify('invalid'));\n\n// All of the following return true:\n\\var_dump(hexRgb\\verify('f00'));\n\\var_dump(hexRgb\\verify('f00f'));\n\\var_dump(hexRgb\\verify('ff0000'));\n\\var_dump(hexRgb\\verify('ff0000ff'));\n\\var_dump(hexRgb\\verify('#f00'));\n\\var_dump(hexRgb\\verify('#f00f'));\n\\var_dump(hexRgb\\verify('#ff0000'));\n\\var_dump(hexRgb\\verify('#ff0000ff'));\n\n// Returns false:\n\\var_dump(hexRgb\\verify('invalid'));\n\n// The following also return false, because they eventually could be mistaken for RGB values:\n\\var_dump(hexRgb\\verify([ 'ff', '00', '00' ]));\n\\var_dump(hexRgb\\verify([ 'ff', '00', '00', 'ff' ]));\n\n// All of the following return true:\n\\var_dump(hsl\\verify('hsl(0,100,50)'));\n\\var_dump(hsl\\verify('hsl(0deg,100%,50%)'));\n\\var_dump(hsl\\verify('hsla(0,100,50,1)'));\n\\var_dump(hsl\\verify('hsla(0deg,100%,50%,1)'));\n\\var_dump(hsl\\verify('color(hsl,0,100,50,1)'));\n\\var_dump(hsl\\verify('color(hsl,0deg,100%,50%,1)'));\n\\var_dump(hsl\\verify('color(hsl 0 100 50 / 1)'));\n\\var_dump(hsl\\verify('color(hsl 0deg 100% 50% / 1)'));\n\n// All of the following return false:\n\\var_dump(hsl\\verify('0,100,50'));\n\\var_dump(hsl\\verify('hsl 0,100'));\n\n// The following also return false, because they eventually could be mistaken for RGB values:\n\\var_dump(hexRgb\\verify([ 0, 100, 50 ]));\n\\var_dump(hexRgb\\verify([ '0deg', '100%', '50%' ]));\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n#### Conversion Functions\n\nEach supported [🌈 Color Space](#-color-spaces) has a complete set of dedicated functions to **convert** into other *color spaces*. These are also accessible under the namespace `Atomicptr\\Color\\Utils\\[space]`:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils\\CSS;\nuse Atomicptr\\Color\\Utils\\RGB;\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns [ 255, 0, 0, 255 ]:\n$rgb = css\\toRgb(CssColor::red);\n\n// Returns [ 0, 100, 50, 100 ]:\n$hsl = rgb\\toHsl(... $rgb);\n\n// Returns [  0.43606574282481, 0.22249319175624, 0.013923904500943, 1 ]\n$xyzD50 = hsl\\toXyzD50(... $hsl);\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n#### Generic Functions\n\n**Color** also offers an ensemble of **generic utilitary functions**, all located under the namespace `Atomicptr\\Color\\Utils`.\n\nIf the majority of these functions are mostly made for interal usages, a few can be useful to you if you prefer to use **Color** with a *functional programming approcach*. These are described below.\n\nThe `constant()` function can be used to access and declare **configuration constants** direclty, without the need to use [the `Constant` Enum](#the-constant-enum):\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils;\n\nrequire 'vendor/autoload.php';\n\n// Returns null:\n\\var_dump(utils\\constant('unknown'));\n\n// Returns 7:\n\\var_dump(utils\\constant('precision', 7));\n\n// Creates the constant with a value of 3, then returns 3:\n\\var_dump(utils\\constant('precision', 3, true));\n\n// Now that the constant was created, always returns 3:\n\\var_dump(utils\\constant('precision'));\n\n```\n\nThe `findColorSpace()` function helps you to guess a [🌈 Color Space](#-color-spaces) by interpreting a provided `$value`.\n\nIf the function succeeds, it returns an instance of [the `ColorSpace` Enum](#the-colorspace-enum).\n\nIn case of failure, the function will throw a `UnknownColorSpace` by default, except if you set the `$throw` parameter to `false` or if you provide a `$fallback` value.\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// Returns ColorSpace::Css:\n$space = utils\\findColorSpace('red');\n\n// Returns ColorSpace::Rgb:\n$space = utils\\findColorSpace('rgba(255,0,0,1)');\n\n// Also returns ColorSpace::Rgb:\n$space = utils\\findColorSpace([ 255, 0, 0, 255 ]);\n\n// Throws a UnknownColorSpace Exception:\n$space = utils\\findColorSpace('invalid');\n\n// Returns ColorSpace::Rgb (using the $fallback parameter):\n$space = utils\\findColorSpace('invalid', ColorSpace::Rgb);\n\n// Returns null (using the $throw parameter):\n$space = utils\\findColorSpace('invalid', throw : false);\n\n```\n\nThe `isColorString()` function returns a **boolean** indicating if the provided `$value` is a valid CSS color string.\n\nBy default it is very tolerant and will return `true` for any string corresponding to a valid CSS syntax, regardless of how you wrote the function name (meaning something like 'myCustomRgb(255,0,0)' will be considered as valid).\n\nIf you want a more precise check, you can use the `$spaces` parameter to provide either:\n\n- an unique stringable value, like `'rgb'` ;\n- an array of accepted values, like `[ 'rgb', 'rgba' ]` ;\n- an instance of [the `ColorSpace` Enum](#the-colorspace-enum) (all of its aliases will be accepted) ;\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// All of the following return true:\n\\var_dump(utils\\isColorString('myCustomColor(255,0,0,1)'));\n\\var_dump(utils\\isColorString('rgb(100% 0% 0% / 100%)', 'rgb'));\n\\var_dump(utils\\isColorString('rgba(255,0,0,1)', [ 'rgb', 'rgba' ]));\n\\var_dump(utils\\isColorString('color(srgb 100% 0% 0% / 100%)', ColorSpace::Rgb));\n\n// All of the following return false:\n\\var_dump(utils\\isColorString('invalid'));\n\\var_dump(utils\\isColorString('rgb 100%'));\n\\var_dump(utils\\isColorString('255,0,0'));\n\\var_dump(utils\\isColorString('rgba(255,0,0,1)', 'rgb'));\n\\var_dump(utils\\isColorString('srgb(255,0,0,1)', [ 'rgb', 'rgba' ]));\n\\var_dump(utils\\isColorString('myCustomRgb( 100% 0% 0% / 100%)', ColorSpace::Rgb));\n\\var_dump(utils\\isColorString('color(myCustomRgb 100% 0% 0% / 100%)', ColorSpace::Rgb));\n\n```\n\nThe `parseColorValue()` function transforms a *CSS color string* into an array of values. If the provided `$value` is not stringable, it will simply be returned as an array.\n\nThe `$opacityFactor` parameter is useful to convert opacity into the correct range (for example converting 1 to 100 or 255).\n\n\u003e **Note** :\n\u003e This function does not *clean* values inside of the array. For a typical usage, you may want to pass its result into the corresponding `clean()` function (see the [Color Space Functions](#color-space-functions) section for more details).\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils;\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns [ 255, 0, 0 ]:\n$values = utils\\parseColorValue('rgb(255,0,0)');\n\n// Returns [ 255, 0, 0, 1 ]:\n$values = utils\\parseColorValue('rgb(255,0,0,1)');\n\n// Returns [ 255, 0, 0, 255 ] (using the $opacityFactor parameter):\n$values = utils\\parseColorValue('rgb(255,0,0,1)', 255);\n\n// Returns [ '100%', '0%', '0%', '100%' ]:\n$values = utils\\parseColorValue('rgb(100% 0% 0% / 100%)');\n\n// Returns [ CssColor::red ]\n$values = utils\\parseColorValue(CssColor::red);\n\n// Returns [ 255, 0, 0, 255 ]:\n$values = utils\\parseColorValue([ 255, 0, 0, 255 ]);\n\n```\n\nThe `to()` function is the highest-level function used to convert any color value to any color space.\n\nIn case of success, its result will always be an array.\n\nIts `$to` and `$from` parameters correspond respectively to the output and input color spaces, and accept either an instance of [the `ColorSpace` Enum](#the-colorspace-enum) or a stringable value corresponding to a *valid color space alias* (you can find all valid aliases listed below in the [🌈 Color Spaces](#-color-spaces) section).\n\nIf these parameters are null, they will be guessed by interpreting the format of `$value` (using the `findColorSpace()` function).\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Utils;\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// Returns [ CssColor::red ]:\n// ('red' is a valid CSS color so we can omit the $from parameter):\n$css = utils\\to('red', 'css');\n\n// Returns [ 255, 0, 0, 255 ]:\n// ([ CssColor::red ] is a valid CSS color so we can omit the $from parameter):\n$rgb = utils\\to($css, ColorSpace::Rgb);\n\n// Returns [ 0, 100, 50, 100 ]:\n// ([ 255, 0, 0, 255 ] is a valid RGB color so we can omit the $from parameter):\n$hsl = utils\\to($rgb, ColorSpace::Hsl);\n\n// Returns [ 54.29054294697, 80.804920334624, 69.890988258963, 100 ]\n// (the $from parameter avoids HSL array being interpreted as RGB):\n$lab = utils\\to($hsl, ColorSpace::Lab, ColorSpace::Hsl);\n\n// Returns [ 54.29054294697, 106.83719104366, 40.857668782131, 100 ]\n// (the $from parameter avoids Lab array being interpreted as RGB):\n$lch = utils\\to($lab, ColorSpace::Lch, ColorSpace::Lab);\n\n// Returns [ 0.41239079028139, 0.21263903420017, 0.01933077971095, 100 ]\n// (the $from parameter avoids Lch array being interpreted as RGB):\n$xyzD65 = utils\\to($lch, ColorSpace::XyzD65, ColorSpace::Lch);\n\n// Returns [ 0.70226883304033, 0.27562276714962, 0.10344904551878, 1 ]\n// (here we use a valid string input so we can omit the $from paramter):\n$proPhoto = utils\\to('color(xyz-d65 0.4124 0.2126 0.0193 / 100%)', ColorSpace::ProPhoto);\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n### 🛠️ Enums and Constants\n\n#### The `Constant` Enum\n\n**Color** can be preconfigured with dedicated **constants**. These act as default values used by multiple functions when the corresponding parameter is missing or set to null. All constants are written in uppercase and prefixed with `COULEUR_`.\n\nCurrently, the following constants are used:\n\n- `COULEUR_LEGACY` (default `0`): if set to `1`, stringified colors will use the *legacy CSS syntax* by default ;\n- `COULEUR_PRECISION` (default `9`): the default rounding precision for color values when stringified ;\n\nYou can use the `Constant` enum to easily access and manage these constants and their values:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\Constant;\n\nrequire 'vendor/autoload.php';\n\n// Returns all Constant cases:\nConstant::cases();\n\n// Always returns 0, which is the default value for the COULEUR_LEGACY constant:\nConstant::LEGACY-\u003evalue;\n\n// Always returns 9, which is the default value for the COULEUR_PRECISION constant:\nConstant::PRECISION-\u003evalue;\n\n// Returns the value of the COULEUR_LEGACY constant if defined, or 0 by default:\nConstant::LEGACY-\u003evalue();\n\n// Returns the value of the COULEUR_PRECISION constant if defined, or 9 by default:\nConstant::PRECISION-\u003evalue();\n\n// Returns the value of the COULEUR_LEGACY constant if defined, or 1 as fallback:\nConstant::LEGACY-\u003evalue(1);\n\n// Returns the value of the COULEUR_PRECISION constant if defined, or 3 as fallback:\nConstant::PRECISION-\u003evalue(3);\n\n// Returns the value of the COULEUR_LEGACY constant if defined, or define it with 1 as value then returns 1:\nConstant::LEGACY-\u003evalue(1, true);\n\n// Returns the value of the COULEUR_PRECISION constant if defined, or define it with 3 as value then returns 3:\nConstant::PRECISION-\u003evalue(3, true);\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n#### The `ColorSpace` Enum\n\nThis enum is the simplest way to access all **color spaces** supported by **Color**:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// Returns all ColorSpace cases:\nColorSpace::cases();\n\n```\n\nYou can access a `ColorSpace` instance by the corresponding color `class`:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorSpace;\nuse Atomicptr\\Color\\Colors\\Lch;\nuse Atomicptr\\Color\\Colors\\LinP3;\nuse Atomicptr\\Color\\Colors\\Rgb;\n\nrequire 'vendor/autoload.php';\n\n// Returns ColorSpace::Lch:\nColorSpace::from(Lch::class);\n\n// Returns ColorSpace::LinP3:\nColorSpace::from(LinP3::class);\n\n// Returns ColorSpace::Rgb:\nColorSpace::from(Rgb::class);\n\n```\n\nEach `ColorSpace` is accessible from multiple **aliases** with the `fromAlias()` method. All aliases are case insensitive:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorSpace;\n\nrequire 'vendor/autoload.php';\n\n// Returns all ColorSpace aliases:\nColorSpace::allAliases();\n\n// Returns aliases of the HexRgb space:\nColorSpace::HexRgb-\u003ealiases();\n\n// Returns ColorSpace::Rgb:\nColorSpace::fromAlias('rgb');\nColorSpace::fromAlias('srgb');\nColorSpace::fromAlias('RGBA');\n\n// Returns ColorSpace::Lab:\nColorSpace::fromAlias('lab');\nColorSpace::fromAlias('cielab');\nColorSpace::fromAlias('CIE-LAB');\n\n```\n\nYou can easily access [dedicated functions](#color-space-functions) from each `ColorSpace` with the `cleanCallback()`, `fromCallback()`, `stringifyCallback()` and `verifyCallback()` methods:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\ColorSpace;\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns 'Atomicptr\\Color\\Utils\\XyzD50\\clean':\nColorSpace::XyzD50-\u003ecleanCallback();\n\n// Returns [ 255, 127.5, 0, 255 ]:\nColorSpace::Rgb-\u003ecleanCallback()('rgb(100%,50%,0)');\n\n// Returns [ 'FF', '00', '00', 'FF' ]:\nColorSpace::HexRgb-\u003ecleanCallback()('#f00');\n\n// Returns 'Atomicptr\\Color\\Utils\\XyzD50\\from':\nColorSpace::XyzD50-\u003efromCallback();\n\n// Returns [ 255, 0, 0, 255 ]:\nColorSpace::Rgb-\u003efromCallback()('hsl(0deg,100%,50%)');\n\n// Returns CssColor::red:\nColorSpace::Css-\u003efromCallback()('#f00');\n\n// Returns 'Atomicptr\\Color\\Utils\\XyzD50\\stringify':\nColorSpace::XyzD50-\u003estringifyCallback();\n\n// Returns 'rgb(100% 0% 0% / 50%):\nColorSpace::Rgb-\u003estringifyCallback()(255, 0 , 0, 127.5);\n\n// Returns '#F00':\nColorSpace::Css-\u003estringifyCallback()(CssColor::red);\n\n// Returns 'Atomicptr\\Color\\Utils\\CSS\\verify':\nColorSpace::Css-\u003everifyCallback();\n\n// Returns true:\nColorSpace::Rgb-\u003everifyCallback()('rgb(100%,50%,0)');\n\n// Returns false:\nColorSpace::HexRgb-\u003everifyCallback()('#ff');\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n#### The `CssColor` Enum\n\nThis enum helps managing `CSS` **named colors**. With its multiple methods, you can easily know if a `CssColor` exists and get the corresponding `RGB` or `HexRGB` coordinates from it:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns all CssColor cases:\nCssColor::cases();\n\n// Returns RGB coordinates for all supported CSS colors:\nCssColor::allRgbCoordinates();\n\n// Returns HexRgb coordinates for all supported CSS colors:\nCssColor::allHexRgbCoordinates();\n\n// Returns true (the 'red' color exists):\nCssColor::exists('red');\n\n// Returns [ 255, 0, 0 ]:\nCssColor::red-\u003etoRgbCoordinates();\n\n// Returns [ 'FF', '00', '00' ]:\nCssColor::red-\u003etoHexRgbCoordinates();\n\n```\n\nThe `fromCss()` method allows you to get a specific `CssColor` by its name. If no supported color matches the `$name` parameter, a `UnsupportedCssColor` Exception will be thrown by default, unless you provide a `$fallback` or you set the `$throw` parameter to **false**.\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns CssColor::red:\nCssColor::fromCss('red');\n\n// Throws a UnsupportedCssColor Exception:\nCssColor::fromCss('unknown');\n\n// Returns CssColor::pink Exception:\nCssColor::fromCss('unknown', CssColor::pink);\n\n// Returns null:\nCssColor::fromCss('unknown', null, false);\n\n```\n\nYou can also find the `CssColor` corresponding to precise `RGB` or `HexRGB` coordinates with `fromRgb()` and `fromHexRgb()`.\n\nBy default these functions will return the supported CSS color which is the **closest** to the provided coordinates, unless you set the `$closest` parameter to **false**. In that case and if no supported color matches the exact coordinates you provided, a `UnsupportedCssColor` Exception will be thrown by default, unless you provide a `$fallback` or you set the `$throw` parameter to **false**.\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns CssColor::red which is the closest to #FA1111:\nCssColor::fromHexRgb('FA', '11', '11');\n\n// Throws a UnsupportedCssColor Exception:\nCssColor::fromHexRgb('FA', '11', '11', false);\n\n// Returns CssColor::pink:\nCssColor::fromHexRgb('FA', '11', '11', false, CssColor::pink);\n\n// Returns null:\nCssColor::fromHexRgb('FA', '11', '11', false, null, false);\n\n// Returns CssColor::red which is the closest to rgb(250,10,10):\nCssColor::fromRgb(250, 10, 10);\n\n// Throws a UnsupportedCssColor Exception:\nCssColor::fromRgb(250, 10, 10, false);\n\n// Returns CssColor::pink:\nCssColor::fromRgb(250, 10, 10, false, CssColor::pink);\n\n// Returns null:\nCssColor::fromRgb(250, 10, 10, false, null, false);\n\n```\n\nYou can **stringify** a `CssColor` with the `toHexRgbString()` and `toRgbString` methods:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns '#F00':\nCssColor::red-\u003etoHexRgbString();\n\n// Returns '#f00' (using the $uppercase parameter):\nCssColor::red-\u003etoHexRgbString(uppercase : false);\n\n// Returns 'F00' (using the $sharp parameter):\nCssColor::red-\u003etoHexRgbString(sharp : false);\n\n// Returns '#F00F' (using the $alpha parameter):\nCssColor::red-\u003etoHexRgbString(true);\n\n// Returns '#FF0000' (using the $short parameter):\nCssColor::red-\u003etoHexRgbString(short : false);\n\n// Returns '#FF0000FF' (using $alpha and $short parameters):\nCssColor::red-\u003etoHexRgbString(true, false);\n\n// Returns '#ff0000ff' (using $alpha, $short and $uppercase parameters):\nCssColor::red-\u003etoHexRgbString(true, false, false);\n\n// Returns 'ff0000ff' (using $alpha, $short, $uppercase and $sharp parameters):\nCssColor::red-\u003etoHexRgbString(true, false, false, false);\n\n// Returns 'rgb(100% 0% 0%)':\nCssColor::red-\u003etoRgbString();\n\n// Returns 'rgb(100% 0% 0% / 100%)' (using the $alpha parameter):\nCssColor::red-\u003etoRgbString(alpha : true);\n\n// Returns 'rgb(255,0,0)' (using the $legacy parameter):\nCssColor::red-\u003etoRgbString(true);\n\n// Returns 'rgba(255,0,0,1)' (using the $legacy and $alpha parameters):\nCssColor::red-\u003etoRgbString(true, true);\n\n```\n\nYou can also get a new `Color` **object** from any `CssColor` by using the `toCss()`, `toHexRgb()` or `toRgb()` method:\n\n```php\n\u003c?php\n\nuse Atomicptr\\Color\\CssColor;\n\nrequire 'vendor/autoload.php';\n\n// Returns a new colors\\Css instance:\nCssColor::red-\u003etoCss();\n\n// Returns a new colors\\HexRgb instance:\nCssColor::red-\u003etoHexRgb();\n\n// Returns a new colors\\Rgb instance:\nCssColor::red-\u003etoRgb();\n\n```\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n## 🌈 Color Spaces\n\n**Color** currently supports the following **color spaces** and formats:\n\n### CSS\n\nIn **Color**, the `Css` color space refers to the  **named colors** according to the [CSS specification](https://drafts.csswg.org/css-color-4/#named-colors). Because they are a predefined and standardized list of exact colors, they all can be accessed easily with [the CssColor Enum](#the-csscolor-enum).\n\n\u003e **Note** :\n\u003e `Css` colors **cannot** have an opacity value. If you want to apply transparency to a `Css` color, you first **have to** convert it into another color space. In the same way, if you convert a color with transparency into its `Css` equivalent, it will **lose** the transparency.\n\n- **ColorSpace enum case** : `ColorSpace::Css` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\Css` ;\n- **Dedicated functions namespace** : `Atomicptr\\Color\\Utils\\CSS` ;\n- **Accepted aliases** : `css`, `html`, `web` ;\n\n### Hexadecimal RGB\n\n- **ColorSpace** case: `ColorSpace::HexRgb` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\HexRgb` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\HexRGB` ;\n- **Accepted aliases** : `hex`, `hexrgb`, `hex-rgb`, `hex_rgb`, `hexadecimal` ;\n- **Coordinates** : `red`, `green`, `blue` ;\n  \n### HSL\n\n- **ColorSpace** case: `ColorSpace::Hsl` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\Hsl` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\HSL` ;\n- **Accepted aliases** : `hsl`, `hsla` ;\n- **Coordinates** : `hue`, `saturation`, `lightness` ;\n  \n### HSV\n\n- **ColorSpace** case: `ColorSpace::Hsv` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\Hsv` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\HSV` ;\n- **Accepted aliases** : `hsv`, `hsb` ;\n- **Coordinates** : `hue`, `saturation`, `value` ;\n  \n### HWB\n\n- **ColorSpace** case: `ColorSpace::Hwb` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\Hwb` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\HWB` ;\n- **Accepted aliases** : `hwb` ;\n- **Coordinates** : `hue`, `whiteness`, `blackness` ;\n\n### Lab\n\n- **ColorSpace** case: `ColorSpace::Lab` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\Lab` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\Lab` ;\n- **Accepted aliases** : `lab`, `cielab`, `cie-lab`, `cie_lab` ;\n- **Coordinates** : `lightness`, `b`, `a` ;\n\n### Lch\n\n- **ColorSpace** case: `ColorSpace::Lch` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\Lch` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\Lch` ;\n- **Accepted aliases** : `lch`, `cielch`, `cie-lch`, `cie_lch` ;\n- **Coordinates** : `lightness`, `chroma`, `hue` ;\n\n### Linear RGB\n\n- **ColorSpace** case: `ColorSpace::LinRgb` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\LinRgb` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\LinRGB` ;\n- **Accepted aliases** : `srgb-linear`, `linrgb`, `linsrgb`, `lin-rgb`, `lin_rgb`, `lin-srgb`, `lin_srgb` ;\n- **Coordinates** : `red`, `green`, `blue` ;\n\n### Linear P3\n\n- **ColorSpace** case: `ColorSpace::LinP3` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\LinP3` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\LinP3` ;\n- **Accepted aliases** : `p3-linear`, `p3_linear`, `linp3`, `lin-p3`, `lin_p3` ;\n- **Coordinates** : `red`, `green`, `blue` ;\n\n### Linear ProPhoto\n\n- **ColorSpace** case: `ColorSpace::LinProPhoto` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\LinProPhoto` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\LinProPhoto` ;\n- **Accepted aliases** : `prophoto-linear`, `prophoto_linear`, `linprophoto`, `lin-prophoto`, `lin_prophoto` ;\n- **Coordinates** : `red`, `green`, `blue` ;\n\n### OkLab\n\n- **ColorSpace** case: `ColorSpace::OkLab` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\OkLab` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\OkLab` ;\n- **Accepted aliases** : `oklab`, `ok-lab`, `ok_lab` ;\n- **Coordinates** : `lightness`, `a`, `b` ;\n\n### OkLch\n\n- **ColorSpace** case: `ColorSpace::OkLch` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\OkLch` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\OkLch` ;\n- **Accepted aliases** : `oklch`, `ok-lch`, `ok_lch` ;\n- **Coordinates** : `lightness`, `chroma`, `hue` ;\n\n### P3\n\n- **ColorSpace** case: `ColorSpace::LinP3` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\LinP3` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\LinP3` ;\n- **Accepted aliases** : `display-p3`, `display_p3`, `p3` ;\n- **Coordinates** : `red`, `green`, `blue` ;\n\n### ProPhoto\n\n- **ColorSpace** case: `ColorSpace::ProPhoto` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\ProPhoto` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\ProPhoto` ;\n- **Accepted aliases** : `prophoto`, `prophoto-rgb`, `prophoto_rgb` ;\n- **Coordinates** : `red`, `green`, `blue` ;\n\n### RGB\n\n- **ColorSpace** case: `ColorSpace::Rgb` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\Rgb` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\RGB` ;\n- **Accepted aliases** : `rgb`, `rgba`, `srgb`, `s-rgb`, `s_rgb` ;\n- **Coordinates** : `red`, `green`, `blue` ;\n\n### XYZ-D50\n\n- **ColorSpace** case: `ColorSpace::XyzD50` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\XyzD50` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\XyzD50` ;\n- **Accepted aliases** : `xyz-d50`, `xyz_d50`, `xyzd50` ;\n- **Coordinates** : `x`, `y`, `z` ;\n\n### XYZ-D65\n\n- **ColorSpace** case: `ColorSpace::XyzD65` ;\n- **Color class** : `Atomicptr\\Color\\Colors\\XyzD65` ;\n- **Dedicated functions** namespace : `Atomicptr\\Color\\Utils\\XyzD65` ;\n- **Accepted aliases** : `xyz-d65`, `xyz_d65`, `xyzd65`, `xyz` ;\n- **Coordinates** : `x`, `y`, `z` ;\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n## 📜 License\n\n**Color** is publicly shared under the **MIT License**. You can freely use it in any project. For more information, please read the included [License File](https://github.com/atomicptr/color/blob/main/LICENSE).\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n\n## ❤️ Thanks\n\nA huge thanks to [Lea Verou](https://github.com/LeaVerou) and [Chris Lilley](https://github.com/svgeesus) for their incredible work and their precise articles on the subject. With a special thanks to Chris for the time and the answers he gave me during the implementation of this library.\n\nAlso since this is a fork, a huge thanks to [Matthieu Masta Denis](https://github.com/matthieumastadenis) for developing the original project.\n\n[↑ Back to Top](#-color-a-modern-php-83-color-library)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicptr%2Fcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomicptr%2Fcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicptr%2Fcolor/lists"}