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

AbandonedArchivedLibrary

cyberalien/color
================

Color library

1.0.0(9y ago)020MITPHPPHP &gt;=5.4

Since Apr 18Pushed 9y ago1 watchersCompare

[ Source](https://github.com/cyberalien/color-php)[ Packagist](https://packagist.org/packages/cyberalien/color)[ Docs](https://www.artodia.com/)[ RSS](/packages/cyberalien-color/feed)WikiDiscussions master Synced 2mo ago

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

Why create yet another color library?
=====================================

[](#why-create-yet-another-color-library)

I needed library that:

- Had similar code on server side (PHP) and client side (browser).
- Had license compatible with commercial projects.

There was no library that matched these requirements.

This library is available in 2 languages to make it usable in both client side web components and server side scripts:

- PHP
- JavaScript, usable in Node.js and in browser. Browser version has no dependencies.

Features
========

[](#features)

Library has only 1 object: Color

Color object represents color. You can:

- Set or get color and color components in RGB and HSL color spaces with optional alpha channel.
- Import/export color from/to different commonly used string formats: hexadecimal, IE hex, rgb(), hsl(), color keywords.
- Mix colors.
- Get luminance and calculate color contrast.

Class automatically converts between color spaces when needed.

Code is optimized for performance. Unusual coding style was used to make code consistent between different programming languages.

Usage
=====

[](#usage)

```
use \CyberAlien\Color;

// Create simple color object, get HEX string
$color = new Color();
$color->setRGB(10, 20, 30);
$color->toHex();

// Create color object from string
$color = Color.fromString('rgba(10, 20, 30, .5)');
$color->getRGBA();

// Change color components in different color spaces
$color = Color.fromString('#f00');
$color->setHue(180);
$color->toString(); // '#00ffff'
$color->toHex(true); // '#0ff' - compressed hex string

// Mix colors
$color = Color.fromString('blue');
$color2 = Color.fromString('red');
$color->mix($color2, 50); // 50% of each color
$color->toKeyword(); // 'purple'

// Manipulate color spaces
$color = Color.fromString('yellow');
$color->setHue($color->getHue() + 180);
$color->setLightness(25);
$color->toHex(); // '#000080'
$color->toHSLString(); // 'hsl(240, 100%, 25%)'

// Calculate contrast between 2 colors
$color = Color.fromString('yellow');
$color2 = Color.fromString('darkblue');
$color->getContrast($color2); // 14.245...

```

Documentation
=============

[](#documentation)

Documentation will be added later, when new website is ready.

For now you can easily figure it out by reading function names and docblocks in src/color.js or lib/color.php Code is well documented.

Color values use following ranges:

- red, green, blue: 0-255
- hue: 0-360
- lightness, saturation: 0-100
- alpha: 0-1

Requirements
============

[](#requirements)

PHP library requires PHP 5.4 or newer version.

JavaScript library is written in ES6, but is compiled into ES5 code for older browsers.

Unit tests
==========

[](#unit-tests)

To run tests run this command:

```
./bin/phpunit

```

or, if you have Node.js installed:

```
npm test

```

License
=======

[](#license)

This library is licensed under MIT license. That means you can use it in both open source and commercial projects.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3314d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0534089f50247dd2425b5ae50a618c61ff7d23a28f755cd0bb43fe8d93d2d707?d=identicon)[cyberalien](/maintainers/cyberalien)

---

Top Contributors

[![cyberalien](https://avatars.githubusercontent.com/u/822287?v=4)](https://github.com/cyberalien "cyberalien (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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