PHPackages                             galaxon/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. galaxon/color

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

galaxon/color
=============

Immutable, memory-efficient PHP Color class with RGB/HSL support, CSS color names, and WCAG accessibility features.

v1.0.1(1mo ago)11MITPHPPHP ^8.4

Since Dec 8Pushed 1mo agoCompare

[ Source](https://github.com/mossy2100/Galaxon-PHP-Color)[ Packagist](https://packagist.org/packages/galaxon/color)[ Docs](https://github.com/mossy2100/Galaxon-PHP-Color)[ RSS](/packages/galaxon-color/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (12)Versions (5)Used By (0)

Galaxon PHP Color
=================

[](#galaxon-php-color)

An immutable, memory-efficient Color class for PHP with support for RGB and HSL color spaces, CSS color names, and WCAG accessibility features.

**[License](LICENSE)** | **[Changelog](CHANGELOG.md)** | **[Documentation](docs/)**

[![PHP 8.4](docs/logo_php8_4.png)](docs/logo_php8_4.png)

---

Description
-----------

[](#description)

This package provides a comprehensive Color class for working with colors in PHP. The class is designed to be:

- **Immutable** - Color values cannot be changed after creation, ensuring predictability and thread safety
- **Memory-efficient** - Colors are stored internally as a 4-byte binary string
- **Feature-rich** - Supports RGB, HSL, hex strings, CSS color names, and accessibility calculations
- **CSS-compatible** - Outputs to modern CSS color formats (hex, rgb, hsl)

---

Development and Quality Assurance / AI Disclosure
-------------------------------------------------

[](#development-and-quality-assurance--ai-disclosure)

[Claude Chat](https://claude.ai) and [Claude Code](https://www.claude.com/product/claude-code) were used in the development of this package. The core classes were designed, coded, and commented primarily by the author, with Claude providing substantial assistance with code review, suggesting improvements, debugging, and generating tests and documentation. All code was thoroughly reviewed by the author, and validated using industry-standard tools including [PHP\_Codesniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer/), [PHPStan](https://phpstan.org/) (to level 9), and [PHPUnit](https://phpunit.de/index.html) to ensure full compliance with [PSR-12](https://www.php-fig.org/psr/psr-12/) coding standards and comprehensive unit testing with 100% code coverage. This collaborative approach resulted in a high-quality, thoroughly-tested, and well-documented package delivered in significantly less time than traditional development methods.

[![Code Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)

---

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

[](#requirements)

- PHP ^8.4
- ext-ctype
- galaxon/core

---

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

[](#installation)

```
composer require galaxon/color
```

---

Quick Start
-----------

[](#quick-start)

```
use Galaxon\Color\Color;

// Create colors from various formats
$red = new Color('red');
$orange = new Color('#ff8000');
$purple = Color::fromRgba(128, 0, 255);
$green = Color::fromHsla(120, 1.0, 0.5);

// Access color properties
$color = new Color('#ff8040');
$color->red;         // 255
$color->hue;         // 20.0
$color->lightness;   // 0.625

// Modify colors (returns new instance)
$darkRed = $red->withLightness(0.3);
$transparent = $red->withAlpha(128);

// Color operations
$mixed = $red->mix($blue, 0.5);
$complement = $red->complement();

// Accessibility
$textColor = $background->bestTextColor();  // 'black' or 'white'
$ratio = $color1->contrastRatio($color2);

// Output formats
echo $color->toHex();        // '#ff8040ff'
echo $color->toRgbString();  // 'rgb(255 128 64 / 1)'
echo $color->toHslString();  // 'hsl(20deg 100% 62.5% / 1)'
```

---

Classes
-------

[](#classes)

### [Color](docs/Color.md)

[](#color)

Immutable class for color manipulation with support for:

- RGB and HSL color spaces with automatic conversion
- CSS color names (147 standard names plus 'transparent')
- Hex string parsing (3, 4, 6, or 8 digits)
- Immutable modification methods (withRed, withHue, etc.)
- Color mixing and complementary colors
- WCAG accessibility calculations (contrast ratio, text color selection)
- Multiple output formats (hex, rgb(), hsl())

---

Testing
-------

[](#testing)

The library includes comprehensive test coverage:

```
# Run all tests
vendor/bin/phpunit

# Run with coverage (generates HTML report and clover.xml)
composer test
```

---

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) for details

---

Support
-------

[](#support)

- **Issues**:
- **Documentation**: See [docs/](docs/) directory for detailed class documentation
- **Examples**: See test files for comprehensive usage examples

For questions or suggestions, please [open an issue](https://github.com/mossy2100/Galaxon-PHP-Color/issues).

---

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for version history and changes.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~38 days

Total

4

Last Release

47d ago

Major Versions

v0.2.0 → v1.0.02026-01-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f9cd1bb5c1b12882db4cb82161c1b5a22e1ccbad8845a54a6ae591647e88c07?d=identicon)[mossy2100](/maintainers/mossy2100)

---

Top Contributors

[![mossy2100](https://avatars.githubusercontent.com/u/371497?v=4)](https://github.com/mossy2100 "mossy2100 (31 commits)")

---

Tags

phpcsscolorrgbhexaccessibilityimmutablewcagcolourhsl

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[ssnepenthe/color-utils

A PHP library for performing SASS-like color manipulations.

631.1M10](/packages/ssnepenthe-color-utils)[tecnickcom/tc-lib-color

PHP library to manipulate various color representations

247.2M9](/packages/tecnickcom-tc-lib-color)[ozdemirburak/iris

PHP library for color manipulation and conversion.

1201.7M16](/packages/ozdemirburak-iris)[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)
