PHPackages                             matthieumastadenis/couleur - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. matthieumastadenis/couleur

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

matthieumastadenis/couleur
==========================

A modern PHP 8.1+ color library, compatible with CSS Color Module Level 4

v0.1.2(3y ago)3038.5k↑10.7%6[3 PRs](https://github.com/matthieumastadenis/couleur/pulls)3MITPHPPHP ~8.1

Since Sep 7Pushed 2y ago2 watchersCompare

[ Source](https://github.com/matthieumastadenis/couleur)[ Packagist](https://packagist.org/packages/matthieumastadenis/couleur)[ RSS](/packages/matthieumastadenis-couleur/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (3)

🎨 Couleur: A modern PHP 8.1+ color library
==========================================

[](#-couleur-a-modern-php-81-color-library)

[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/matthieumastadenis/couleur/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/53165313ac25a926cba99e021d87411222e2053d5fdb781c24298f278a7163a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d617474686965756d6173746164656e69732f636f756c6575723f7374796c653d666c6174)](https://packagist.org/packages/matthieumastadenis/couleur)[![Lines of Code](https://camo.githubusercontent.com/d1c1f1d73ef56e5d910de06d106bbc66613760a5f9be0d9a933031d0f409e739/68747470733a2f2f696d672e736869656c64732e696f2f746f6b65692f6c696e65732f6769746875622f6d617474686965756d6173746164656e69732f636f756c6575723f7374796c653d666c6174)](https://github.com/matthieumastadenis/couleur)[![Release date](https://camo.githubusercontent.com/d7ac2bee4177cb195d85aba49041e473fa48e1dda962fe6f6d9a5d928a3f7807/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652d7072652f6d617474686965756d6173746164656e69732f636f756c6575722e7376673f7374796c653d666c6174)](https://github.com/matthieumastadenis/couleur)[![Last commit on main branch](https://camo.githubusercontent.com/01d743a6b683cd01f3474a6958980d420390a359c66a61e564123c7e0a1256a8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6d617474686965756d6173746164656e69732f636f756c6575722f6d61696e2e7376673f7374796c653d666c6174)](https://github.com/matthieumastadenis/couleur)[![Latest Version on Packagist](https://camo.githubusercontent.com/3ed516935a790d5eccca7bb6be16aa90fa049c57e00fca8d74bf429f9e073105/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617474686965756d6173746164656e69732f636f756c6575722e7376673f7374796c653d666c6174)](https://packagist.org/packages/matthieumastadenis/couleur)

- [🎨 Couleur: A modern PHP 8.1+ color library](#-couleur-a-modern-php-81-color-library)
    - [👋 Presentation](#-presentation)
    - [⚙️ Installation](#%EF%B8%8F-installation)
    - [🏁 Quick Start](#-quick-start)
    - [📚 Usage](#-usage)
        - [🏭 Immutable Objects and the `ColorFactory`](#-immutable-objects-and-the-colorfactory)
            - [Direct instanciation](#direct-instanciation)
            - [Using the `ColorFactory`](#using-the-colorfactory)
            - [Using immutable color objects](#using-immutable-color-objects)
        - [🧰 Pure Functions](#-pure-functions)
            - [Color Space Functions](#color-space-functions)
            - [Conversion Functions](#conversion-functions)
            - [Generic Functions](#generic-functions)
        - [🛠️ Enums and Constants](#%EF%B8%8F-enums-and-constants)
            - [The `Constant` Enum](#the-constant-enum)
            - [The `ColorSpace` Enum](#the-colorspace-enum)
            - [The `CssColor` Enum](#the-csscolor-enum)
    - [🌈 Color Spaces](#-color-spaces)
        - [CSS](#css)
        - [Hexadecimal RGB](#hexadecimal-rgb)
        - [HSL](#hsl)
        - [HSV](#hsv)
        - [HWB](#hwb)
        - [Lab](#lab)
        - [Lch](#lch)
        - [Linear RGB](#linear-rgb)
        - [Linear P3](#linear-p3)
        - [Linear ProPhoto](#linear-prophoto)
        - [OkLab](#oklab)
        - [OkLch](#oklch)
        - [P3](#p3)
        - [ProPhoto](#prophoto)
        - [RGB](#rgb)
        - [XYZ-D50](#xyz-d50)
        - [XYZ-D65](#xyz-d65)
    - [🤝 Contributing](#-contributing)
    - [📜 License](#-license)
    - [❤️ Thanks](#%EF%B8%8F-thanks)

👋 Presentation
--------------

[](#-presentation)

**Couleur** is a modern **PHP 8.1+ 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).

The 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/).

**Couleur** 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:

- If you prefer **OOP**, you can use [🏭 Immutable Objects and the `ColorFactory`](#-immutable-objects-and-the-colorfactory) ;
- If you prefer **FP**, you can directly use the multiple [🧰 Pure Functions](#-pure-functions) ;

> **Warning**: This package is currently under development.
>
> The current version may include bugs, untested code, undocumented code, unfinished code, or simply code that will change. More specifically, for the moment there is a lack of *unit tests*, and a few *color spaces* as well as *distance calculation functions* and *gammut correction* remain to be implemented. All of these will come soon.
>
> In the meantime, it is recommended to avoid using this package in production.

[↑ Back to Top](#-couleur-a-modern-php-81-color-library)

⚙️ Installation
---------------

[](#️-installation)

Use the following command to add **Couleur** to your project with [Composer](https://getcomposer.org/):

```
composer require matthieumastadenis/couleur
```

Don't forget to include the [autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading) provided by Composer:

```
