PHPackages                             awcode/awcolor - 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. awcode/awcolor

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

awcode/awcolor
==============

Modern PHP color management library with conversions, manipulation, schemes and WCAG accessibility helpers across hex, rgb(a), hsl(a), hsv, cmyk and CSS named colors.

0.0.1(8y ago)154MITPHPPHP &gt;=5.3.0CI failing

Since Sep 14Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/awcode/awColor)[ Packagist](https://packagist.org/packages/awcode/awcolor)[ Docs](https://github.com/awcode/awColor)[ RSS](/packages/awcode-awcolor/feed)WikiDiscussions master Synced today

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

awColor
=======

[](#awcolor)

A modern, dependency-free PHP color management library: convert, manipulate, build palettes and check accessibility across hex, rgb(a), hsl(a), hsv, cmyk and CSS named colors.

[![CI](https://github.com/awcode/awColor/actions/workflows/ci.yml/badge.svg)](https://github.com/awcode/awColor/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/3cf0c7d0b0f702af7ef64b4e8eb03362c3abb75bac86cce6d2fe92de8988472f/68747470733a2f2f706f7365722e707567782e6f72672f6177636f64652f6177436f6c6f722f76657273696f6e2e706e67)](https://packagist.org/packages/awcode/awColor)[![Total Downloads](https://camo.githubusercontent.com/096adad68f8ec027460fb4856a83e5010801ba1685baa6f1a1cc9c36ae9738b8/68747470733a2f2f706f7365722e707567782e6f72672f6177636f64652f6177436f6c6f722f642f746f74616c2e706e67)](https://packagist.org/packages/awcode/awColor)[![License](https://camo.githubusercontent.com/1c65d9c21e66bc503ede3ab227855461086539b7d695f48284ae689aca35f46c/68747470733a2f2f706f7365722e707567782e6f72672f6177636f64652f6177436f6c6f722f6c6963656e7365)](https://packagist.org/packages/awcode/awColor)

Requirements
------------

[](#requirements)

- PHP **8.2**, **8.3** or **8.4**
- No runtime dependencies

Installation
------------

[](#installation)

```
composer require awcode/awcolor
```

Quick start
-----------

[](#quick-start)

```
use AWcode\awColor;

// Construct from any common format
$color = new awColor('#ff0000');                  // hex (3, 4, 6 or 8 digits)
$color = awColor::fromString('rgb(255, 0, 0)');   // CSS rgb()/rgba()/hsl()/hsla()
$color = awColor::fromName('rebeccapurple');      // CSS3/CSS4 named color
$color = awColor::fromHsl(120, 1.0, 0.5);         // HSL factory
$color = awColor::fromHsv(0, 1.0, 1.0);           // HSV
$color = awColor::fromCmyk(0, 1, 1, 0);           // CMYK
$color = awColor::random();                       // Random opaque color

echo $color;                            // "#ff0000" (Stringable)
echo $color->getRgbaString();           // "rgba(255, 0, 0, 1)"
echo $color->getHslString();            // "hsl(0, 100%, 50%)"
print_r($color->getHsv());              // [0, 1.0, 1.0]
print_r($color->getCmyk());             // [0.0, 1.0, 1.0, 0.0]
```

Manipulation (immutable, chainable)
-----------------------------------

[](#manipulation-immutable-chainable)

```
$color->lighten(0.1);          // +10% lightness
$color->darken(0.1);
$color->saturate(0.2);
$color->desaturate(0.2);
$color->rotate(60);            // hue rotation in degrees
$color->invert();
$color->grayscale();
$color->mix($other, 0.5);      // blend two colors
$color->tint(0.2);             // mix toward white
$color->shade(0.2);            // mix toward black
$color->fadeIn(0.1);
$color->fadeOut(0.1);
```

Palettes
--------

[](#palettes)

```
$color->complement();          // single complementary awColor
$color->triadic();             // [base, +120°, +240°]
$color->tetradic();            // 4 colors at 90° spacing
$color->splitComplementary();  // [base, +150°, +210°]
$color->analogous(5, 20);      // 5 evenly spaced neighbors
$color->monochromatic(7);      // 7 luminance steps
```

WCAG accessibility
------------------

[](#wcag-accessibility)

```
$fg = new awColor('#222');
$bg = new awColor('#fff');

$fg->luminance();              // WCAG 2.x relative luminance (0-1)
$fg->contrastRatio($bg);       // 21.0 for max contrast
$fg->isAccessible($bg);        // AA, normal text  (>= 4.5)
$fg->isAccessible($bg, 'AAA'); // AAA, normal text (>= 7.0)
$fg->isAccessible($bg, 'AA', 'large'); // AA, large text (>= 3.0)

// Pick the best foreground for a given background
$bg->pickReadable(new awColor('#000'), new awColor('#fff'));
```

Comparison &amp; serialization
------------------------------

[](#comparison--serialization)

```
$a->equals($b);
$a->distance($b);              // Euclidean distance in RGB space
$color->toArray();             // ['hex' => ..., 'rgb' => ..., 'hsl' => ..., 'alpha' => ...]
$color->toJson();
```

Backwards compatibility
-----------------------

[](#backwards-compatibility)

The original public API is preserved:

- `new awColor($hex)` / `new awColor($r, $g, $b)` / `new awColor($h, $s, $l, true)`
- Static helpers `formatHex`, `rgbToHex`, `hexToRgb`, `rgbToHsl`, `hslToRgb`, `hexToHsl`, `hslToHex`
- Instance helpers `getHex/getRgb/getR/G/B/getHsl/getH/S/L`, `setHex/setRgb/setHsl/setR/G/B`, `isLight/isDark/isGrey`, `complementary()`

Two long-standing bugs were fixed in the process:

- `hslToRgb()` now returns 0-255 integers instead of 0-1 floats (which caused `rgbToHex()` to always return black for HSL-derived values).
- `setHsl()` previously wrote to a typo'd `_rbg` property — it now correctly updates `_rgb` and `_hex`.

Testing
-------

[](#testing)

```
composer install
composer test
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance58

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.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

Unknown

Total

1

Last Release

3215d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad0d81e88f801bc74aff0fd0c82cbfc86ab0853ebf0a4b12b39a96fe05f00cf2?d=identicon)[mnwalker](/maintainers/mnwalker)

---

Top Contributors

[![mnwalker](https://avatars.githubusercontent.com/u/9032080?v=4)](https://github.com/mnwalker "mnwalker (8 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (1 commits)")

---

Tags

colorrgbhexhsl

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/awcode-awcolor/health.svg)

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

###  Alternatives

[ozdemirburak/iris

PHP library for color manipulation and conversion.

1201.9M23](/packages/ozdemirburak-iris)[ssnepenthe/color-utils

A PHP library for performing SASS-like color manipulations.

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

A little library to handle color conversions

38221.2M36](/packages/spatie-color)[tecnickcom/tc-lib-color

PHP library to manipulate various color representations

247.9M26](/packages/tecnickcom-tc-lib-color)[fjw/color-compare

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

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

PHPackages © 2026

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