PHPackages                             intellex/color - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. intellex/color

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

intellex/color
==============

2.0.0(2y ago)2571MITPHPPHP &gt;=7.4

Since Mar 3Pushed 2y ago1 watchersCompare

[ Source](https://github.com/IntellexApps/color)[ Packagist](https://packagist.org/packages/intellex/color)[ RSS](/packages/intellex-color/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Color manipulation for PHP
==========================

[](#color-manipulation-for-php)

- Supports **RGB(A)** and **CMY(K)**, with **super** easy conversion.
- **Modify** initialized color using the **available setters**.
- Output colors to **any format**, including every **CSS** one.
- Ability to **parse** colors from any **standard** and **CSS** notation.
- Extend parsing with your own **custom parsers**.
- Predefined list of **142 named** web colors.
- **No** additional **3rd party** scripts.

Predefined colors
-----------------

[](#predefined-colors)

The list of all 142 standardized HTML colors defined in `Predefined\RGBA` class:

```
$chocolateColor = RGBA::Chocolate();
$mistyRoseColor = RGBA::MistyRose();
$navyColor = RGBA::Navy();
```

A couple of examples
--------------------

[](#a-couple-of-examples)

From hex to CSS:

```
$color = ColorParser::parse('#781190');
echo $color->toCSS();
```

From CSS to GD color:

```
$color = ColorParser::parse('rgb(80, 138, 99);');
$image = imageCreateTrueColor(200, 200);
$gdColor = $color->getRGBA()->toImageColorIdentifier($image)
```

From CMYK to RGBA:

```
$color = ColorParser::parse('cmyk(20%, 40%, 60%, 20%');
echo $color->getRGBA()->toHexString();
```

Conversion
----------

[](#conversion)

When initialize a color will either be RGBA or CMYK. This can be done manually, or by parsing the string.

Note that some parameters (ie. alpha channel in RGBA), will simply be ignored during conversion.

Any color can be cast to another one:

```
$rgba = new RGBA(190, 11, 32, 0.65);
$cmyk = $rgba->getCMYK();
```

Example with a [parser](#parsing-a-color).

```
$rgba = ColorParser::parse($input)->getRGBA();
```

Output
------

[](#output)

Options available for RGBA:

```
$rgba->toImageColorIdentifier($image);
$rgba->toHexString($includeAlpha, $includeHashTag, $uppercase);
$rgba->toCSS();
$rgba->getCMYK();
```

Options available for CMYK:

```
$cmyk->toCSS;
$cmyk->getRGBA;
```

Parsing a color
---------------

[](#parsing-a-color)

Use `ColorParser::parse($input)`, which will try every registered parser.

If no parser is able to handle it, `ColorCannotBeParsed` will be thrown.

Default parsers support most (if not all) RGBA and CMYK formats, but you can create you [custom parsers](#custom-parsers) for your specific need.

Supported out of the box:

- **CMYK** from array `[C, M, Y]` and `[C, M, Y, K]`
- **RGB(A)** from array `[R, G, B]` and `[R, G, B, A]`
- **RGB(A)** from string:
    - `RGB`
    - `ARGB`
    - `RRGGBB`
    - `AARRGGBB`
    - `#RGB`
    - `#ARGB`
    - `#RRGGBB`
    - `#AARRGGBB`
- **CSS**
    - `cmyk(c%, m%, y%)` and `cmyk(c%, m%, y%, k%)`
    - `rgb(r, b, g)` and `rgb(r, b, g, a)`

Custom parsers
--------------

[](#custom-parsers)

Create and register a new parsers, that will ba included in the next parsing:

1. Create a class and implement `AbstractColorParser` interface.
2. When implementing method `parse($input`)
    - if input cannot be parsed -&gt; throw `ColorCannotBeParsed`
    - if input can be parsed return the `Color`
3. Register the parser with `ColorParser::registerParser(AbstractColorParser $parser)`.
4. Next time the `ColorParser::parse()` is called, your parser will be considered as well.

TODO
----

[](#todo)

1. Support for HSV.
2. Detect color name by finding the most similar color in the predefined list.

Credits
-------

[](#credits)

Script has been written by the [Intellex](https://intellex.rs/en) team.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity61

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1751 days

Total

2

Last Release

877d ago

Major Versions

v1.0.0 → 2.0.02023-12-19

PHP version history (2 changes)v1.0.0PHP &gt;=5.6

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/1008e18d1b96b552ce1b76dccf9d1d49d1658835cae153cd53c784a846121d2d?d=identicon)[intellexapps](/maintainers/intellexapps)

---

Tags

phpcsscolorrgbparsingcmykrgbaintellex

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/intellex-color/health.svg)

```
[![Health](https://phpackages.com/badges/intellex-color/health.svg)](https://phpackages.com/packages/intellex-color)
```

###  Alternatives

[ozdemirburak/iris

PHP library for color manipulation and conversion.

1201.7M16](/packages/ozdemirburak-iris)[tecnickcom/tc-lib-color

PHP library to manipulate various color representations

247.2M9](/packages/tecnickcom-tc-lib-color)[gravitypdf/querypath

PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP 7.1 to 8.5 support

281.2M1](/packages/gravitypdf-querypath)[ssnepenthe/color-utils

A PHP library for performing SASS-like color manipulations.

631.1M10](/packages/ssnepenthe-color-utils)[matecat/xliff-parser

A Xliff parser written in PHP

14127.5k](/packages/matecat-xliff-parser)[fjw/color-compare

A library for converting colors (Hex, RGB, HSL, CIELAB (LAB), DIN-99) and calculating color distances based on DIN-99.

1310.0k](/packages/fjw-color-compare)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
