PHPackages                             fjw/color-compare - 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. fjw/color-compare

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

fjw/color-compare
=================

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

1.1(7y ago)1310.8k↓20.3%2MITPHPPHP &gt;=7.2.0

Since Jun 5Pushed 3y agoCompare

[ Source](https://github.com/fjw/ColorCompare)[ Packagist](https://packagist.org/packages/fjw/color-compare)[ RSS](/packages/fjw-color-compare/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

ColorCompare
============

[](#colorcompare)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Build Status](https://camo.githubusercontent.com/38ece20c3d9c5f6da6d523b82ba0877c283bfab6b558e2480279e09c1ab908de/68747470733a2f2f7472617669732d63692e636f6d2f666a772f436f6c6f72436f6d706172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/fjw/ColorCompare)

ColorCompare is a library to convert colors from hex, RGB, HSL, CIE L\*a\*b\* (LAB) and DIN-99 into one another and calculate color distances (human visual difference) using the DIN-99 methedology.

You can get the library from [packagist](https://packagist.org/packages/fjw/color-compare):

```
composer require fjw/color-compare

```

How to use
----------

[](#how-to-use)

You can get the DIN-99 visual difference (distance) of two colors easily:

```
use ColorCompare\Color;

$color1 = new Color("#aaff05");
$color2 = new Color("#CCC");

$difference = $color1->getDifference($color2);
```

You can convert each format into one another:

```
use ColorCompare\Color;

$color = new Color("#aaff05");

$hex = $color->getHex(); // just to show off, it already was Hex ;)
$rgb = $color->getRgb(); // [ "r" => 170, "g" => 255, "b" => 5 ]
$hsl = $color->getHsl(); // [ "h" => 80.4, "s" => 1.0, "l" => 0.51 ]
$lab = $color->getLab(); // [ "L" => 91.72, "a" => -54.41, "b" => 87.65 ]
$din99 = $color->getDin99(); // [ "L99" => 94.51, "a99" => -12.31, "b99" => 30.39 ]
```

You can create the color object by Hex, RGB, HSL and LAB:

```
use ColorCompare\Color;

$color = new Color([
    "h" => 300,
    "s" => 0.5,
    "l" => 1
]);

$hex = $color->getHex();
```

Visual Color Distance with DIN-99
---------------------------------

[](#visual-color-distance-with-din-99)

DIN-99 differences, returned by Color::getDifference(), can better calculate the human visual difference than LAB with delta-E. There are also superior distance calculations like CIE94 or CIEDE2000 but these are complicated and need intensive calculations. With DIN-99 the calculation is done beforehand and needs less ressources. When your color is already converted into DIN-99 you can just calculate the euklidean distance and get the same quality.

```
sqrt(($c2["L99"] - $c1["L99"])**2 +
    ($c2["a99"] - $c1["a99"])**2 +
    ($c2["b99"] - $c1["b99"])**2);
```

This is a huge advantage! If you would like, per example, make a client side filter of colored products (or whatever) you can convert your data into DIN-99 on the server side and only need to do the easier euklidean calculation in your JavaScript.

Sources (german):

[http://www.germancolorgroup.de/html/Vortr\_02\_pdf/GCG\_%202002\_%20Buering.pdf](http://www.germancolorgroup.de/html/Vortr_02_pdf/GCG_%202002_%20Buering.pdf)

Example Code
------------

[](#example-code)

Just run `./devserver.sh` if you have PHP-CLI and open `http://localhost:8000` to see the difference calculation in action.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.9% of commits — single point of failure

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 ~0 days

Total

2

Last Release

2585d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/43d952be437b0c6db251639eb992a4e1fc2a7d550c77b923fc73b77e8644fddc?d=identicon)[fjw12345](/maintainers/fjw12345)

---

Top Contributors

[![fjw](https://avatars.githubusercontent.com/u/673476?v=4)](https://github.com/fjw "fjw (31 commits)")[![Invincibear](https://avatars.githubusercontent.com/u/6895337?v=4)](https://github.com/Invincibear "Invincibear (1 commits)")

---

Tags

colordin99distance-calculationhsllabphpphp7rgbphpcolorrgbcomparedistancehsllabcolor distancevisual differencedin99

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[ozdemirburak/iris

PHP library for color manipulation and conversion.

1201.9M23](/packages/ozdemirburak-iris)[tecnickcom/tc-lib-color

PHP library to manipulate various color representations

247.9M25](/packages/tecnickcom-tc-lib-color)[ssnepenthe/color-utils

A PHP library for performing SASS-like color manipulations.

631.2M16](/packages/ssnepenthe-color-utils)

PHPackages © 2026

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