PHPackages                             netherphp/dye - 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. netherphp/dye

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

netherphp/dye
=============

Simple colour formatting and manipulation.

01.1k2PHP

Since Jun 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/netherphp/dye)[ Packagist](https://packagist.org/packages/netherphp/dye)[ RSS](/packages/netherphp-dye/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (2)

Nether\\Dye
===========

[](#netherdye)

[![Packagist](https://camo.githubusercontent.com/b98e6aba8df5ce524d7f824a7891bfedc10d6c9338e0007072625650126971ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65746865727068702f6479652e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/netherphp/dye)[![Build Status](https://camo.githubusercontent.com/fdc15d61764e665a944e74832fdadf6b523185e7b2ccf318305e2c2d79be7b87/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e65746865727068702f6479652f706870756e69742e796d6c3f7374796c653d666f722d7468652d6261646765)](https://github.com/netherphp/dye/actions)[![codecov](https://camo.githubusercontent.com/ef0cd75a9edde360a0d1369e494f20bf8d44dfdbe24bf3e24c6364d4d6b7a244/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f6e65746865727068702f6479653f7374796c653d666f722d7468652d626164676526746f6b656e3d5651433438584e425332)](https://codecov.io/gh/netherphp/dye)

Simple colour parsing and manipulation library. Lightweight, dependency free. Able to automatically parse common colour strings. No messing around with different classes for the various supported formats.

#### Supported String Formats

[](#supported-string-formats)

- RGB Hex String `#FF0000`
- RGBA Hex String `#FF0000FF`
- RGB CSS String `rgb(255, 0, 0)`
- RGBA CSS String `rgba(255, 0, 0, 1.0)`
- HSL CSS String `hsl(255, 0, 0)`
- HSLA CSS String `hsla(255, 0, 0, 1.0)`

```
use Nether\Dye\Colour;

$Red = new Colour('#FF0000');
// ...
```

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

[](#requirements)

- PHP 8.1+

Classes
=======

[](#classes)

### `Nether\Dye\Colour`

[](#netherdyecolour)

Basic colour object where modifications will be mixed into the current object and all relevant properties recalculated to remain current.

### `Nether\Dye\ColourImmutable`

[](#netherdyecolourimmutable)

Same API as `Colour` except all methods that would have modified the current dataset return new objects leaving the original unaltered.

Factory API
===========

[](#factory-api)

**`Colour::From(string|RGBA|HSLA $Input): static`**

- Parse input colour from strings fitting known formats.

**`Colour::FromIntRGB(int $RGB): static`**

- Parse input colour from 24bit RGB integer.

**`Colour::FromIntRGBA(int $RGB): static`**

- Parse input colour from 32bit RGBA integer.

**`Colour::FromRGB(int $R, int $G, int $B, int|float $A=255): static`**

- Parse RGB by component.

**`Colour::FromHSL(int $H, float $S, float $L, float $A=1.0): static`**

- Parse HSL by component.

Manipulation API
================

[](#manipulation-api)

#### Setting Components

[](#setting-components)

**`$Colour->SetRGB(?int $R, ?int $G, ?int $B, ?int $A): self`**

- Set any of the RGB\[A\] components that are specified and not null.

**`$Colour->SetHSL(?int $H, ?float $S, ?float $L, ?float $A): self`**

- Set any of the HSL\[A\] components that are specified and not null.

#### Shooping Around.

[](#shooping-around)

**`$Colour->HueRotate(int $Degrees): self`**

- Hue rotate a colour the specified number of degrees.

**`$Colour->HueShift(float $Percent): self`**

- Hue rotate a colour shifted over by the specified percentage.

**`$Colour->Saturation(float $Mult): self`**

- Modify the saturation of the colour by the specified multiplier.

**`$Colour->Saturate(float $Str): self`**

- Increase the saturation by the specified strength.

**`$Colour->Desaturate(float $Str): self`**

- Reduce the saturation by the specified strength.

**`$Colour->Lightness(float $Mult): self`**

- Modify the lightness of the colour by the specified multiplier.

**`$Colour->Lighten(float $Str): self`**

- Increase the lightness by the specified strength.

**`$Colour->Darken(float $Str): self`**

- Reduce the lightness by the specified strength.

**`$Colour->Mix(Colour $With, float $Str=0.5): self`**

- Blend the specified colour with this one at the specified strength.

Query API
=========

[](#query-api)

**`$Colour->IsBright(): bool`**

- Returns TRUE if the colour would be perceived as bright.

**`$Colour->IsDark(): bool`**

- Returns TRUE if the colour would be perceived as dark.

Printing API
============

[](#printing-api)

**`$Colour->ToHexRGB(): string`**

- Return a hex encoded string like `#FF0000`

**`$Colour->ToHexRGBA(): string`**

- Return a hex encoded string like `#FF0000FF`

**`$Colour->ToStyleRGB(): string`**

- Return a hex encoded string like `rgb(255, 0, 0)`

**`$Colour->ToStyleRGBA(): string`**

- Return a hex encoded string like `rgb(255, 0, 0, 1.00)`

**`$Colour->ToStyleHSL(): string`**

- Return a hex encoded string like `hsl(0, 1.00, 0.50)`

**`$Colour->ToStyleHSLA(): string`**

- Return a hex encoded string like `hsl(0, 1.00, 0.50, 1.0)`

Format Component API
====================

[](#format-component-api)

> Note: all manipulations should be done via the methods on the root colour object to keep the various properties in sync. The SetRGB() and SetHSL() methods accept optional labeled arguments and array splattering.

**`$Colour->RGB->ToArray(bool $Indexed=TRUE): array`**

- Return an indexed array or a list of RGB data.

**`$Colour->RGB->R(): int`**

- Return the Red component of the RGB data.

**`$Colour->RGB->G(): int`**

- Return the Green component of the RGB data.

**`$Colour->RGB->B(): int`**

- Return the Blue component of the RGB data.

**`$Colour->RGB->A(): int`**

- Return the Alpha component of the RGB data.

**`$Colour->HSL->ToArray(bool $Indexed=TRUE): array`**

- Return an indexed array or a list of HSL data.

**`$Colour->HSL->H(): int`**

- Return the Hue component of the HSL data.

**`$Colour->HSL->S(): float`**

- Return the Saturation component of the HSL data.

**`$Colour->HSL->L(): float`**

- Return the Lightness component of the HSL data.

**`$Colour->HSL->A(): float`**

- Return the Alpha component of the HSL data.

Examples
========

[](#examples)

> **Instantiation Choices**

```
use Nether\Dye\Colour;

// long form
$C1 = new Colour;
$C1->Import('#aabbcc');

// condensed form
$C2 = new Colour('#aabbcc');

// factory form
$C3 = Colour::From('#aabbcc');
```

> **Immutables**

```
use Nether\Dye\ColourImmutable;

$R = new ColourImmutable('#FF0000');
$G = $R->HueRotate(120);
$B = $G->HueRotate(120);

printf(
	'R: %s, G: %s, B: %s%s',
	$R->ToHexRGB(),
	$G->ToHexRGB(),
	$B->ToHexRGB(),
	PHP_EOL
);

// R: #FF0000, G: #00FF00, B: #0000FF
```

Testing
=======

[](#testing)

**`$ phpunit`**

- Run the unit test suite.

**`$ php -S localhost:8080 -t wwwtest`**

- Run a test page to see some things.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![bobmagicii](https://avatars.githubusercontent.com/u/881944?v=4)](https://github.com/bobmagicii "bobmagicii (72 commits)")

### Embed Badge

![Health badge](/badges/netherphp-dye/health.svg)

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

###  Alternatives

[parsilver/thailand-provinces-php

Thailand address database

121.5k1](/packages/parsilver-thailand-provinces-php)

PHPackages © 2026

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