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

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

scripturadesign/color
=====================

Working with colors

0.1.3(9y ago)073.9k↓67.4%1MITPHPPHP ^5.6|^7.0

Since Oct 2Pushed 9y ago1 watchersCompare

[ Source](https://github.com/scripturadesign/color)[ Packagist](https://packagist.org/packages/scripturadesign/color)[ Docs](https://github.com/scripturadesign/color)[ RSS](/packages/scripturadesign-color/feed)WikiDiscussions master Synced 2d ago

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

Color
=====

[](#color)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1477922498a4db51636d36a9c888075499287542a08227c21eb4cf4d331967b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73637269707475726164657369676e2f636f6c6f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/scripturadesign/color)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/24074aa0eac8dfe4f82be9ff44ea602193d64764065057f47603a61fc51f41d0/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73637269707475726164657369676e2f636f6c6f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/scripturadesign/color)[![Coverage Status](https://camo.githubusercontent.com/e071a66b085130f181b5a8904a9a845610389ccb8342511776831e9b23bf9e27/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f73637269707475726164657369676e2f636f6c6f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/scripturadesign/color/code-structure)[![Quality Score](https://camo.githubusercontent.com/b661936d3d284f35ff644a2fe8eeb72acdbb89bc66d250aadbfea6970008633e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73637269707475726164657369676e2f636f6c6f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/scripturadesign/color)[![Code Climate](https://camo.githubusercontent.com/0e15a4c5eddd81745e69155b7d7a6d16dead1d735bc3b94b7e46c43001f49b2e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f73637269707475726164657369676e2f636f6c6f722e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/scripturadesign/color)[![Total Downloads](https://camo.githubusercontent.com/8c8219084d5708f768bddc123c94529e0966435acaf36966be2ab16e0e2a7568/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73637269707475726164657369676e2f636f6c6f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/scripturadesign/color)

Color is a package to convert between color types.

Install
-------

[](#install)

Via Composer

```
$ composer require scripturadesign/color
```

Usage
-----

[](#usage)

### HEX

[](#hex)

> *Hexadecimal*

```
$hex = new \Scriptura\Color\Types\HEX('ff0000'); // New HEX color
$hex = new \Scriptura\Color\Types\HEX('ff0000', '#{code}'); // New HEX color with template
echo $hex->code(); // 'FF0000'
echo $hex; // '#FF0000'
echo $hex->withTemplate('color: #{code};'); // 'color: #FF0000;'

$hex  = $hex->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX
$rgb  = $hex->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB
$hsl  = $hex->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL
$c256 = $hex->to256(); // Convert the color to \Scriptura\Color\Types\C256
```

#### Default template

[](#default-template)

`#{code}`

#### Sanitizing

[](#sanitizing)

HEX does some sanitizing to support all the various ways a hex color can be written.

Example:

```
123       => '112233'
987654    => '987654'
'aBc'     => 'AABBCC'
'FeDcBa'  => 'FEDCBA'
'#1B5'    => '11BB55'
'#1a2b3c' => '1A2B3C'

```

### RGB

[](#rgb)

> *Red, Green, Blue*

```
$rgb = new \Scriptura\Color\Types\RGB(255, 0, 0); // New RGB color
$rgb = new \Scriptura\Color\Types\RGB(255, 0, 0, '{red},{green},{blue}'); // New RGB color with template
echo $rgb->red(); // 255
echo $rgb->green(); // 0
echo $rgb->blue(); // 0
echo $rgb->rgb(); // [255, 0, 0]
echo $rgb; // '255,0,0'
echo $rgb->withTemplate('color: rgb({red}, {green}, {blue});'); // 'color: rgb(255, 0, 0);'

$rgb = $rgb->withRed(0); // New instance with red set to 0
$rgb = $rgb->withGreen(255); // New instance with green set to 255
$rgb = $rgb->withBlue(255); // New instance with blue set to 255

$hex  = $rgb->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX
$rgb  = $rgb->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB
$hsl  = $rgb->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL
$c256 = $rgb->to256(); // Convert the color to \Scriptura\Color\Types\C256
```

#### Default template

[](#default-template-1)

`{red},{green},{blue}`

### HSL

[](#hsl)

> *Hue, Saturation, Lightness*

```
$hsl = new \Scriptura\Color\Types\HSL(0, 100, 50); // New HSL color
$hsl = new \Scriptura\Color\Types\HSL(0, 100, 50, '{hue}° {saturation}% {lightness}%'); // New HSL color with template
echo $hsl->hue(); // 0
echo $hsl->saturation(); // 100
echo $hsl->lightness(); // 50
echo $hsl->hsl(); // [0, 100, 50]
echo $hsl; // '0° 100% 50%'
echo $hsl->withTemplate('color: ({hue}, {saturation}%, {lightness}%);'); // 'color: hsl(0, 100%, 50%);'

$hsl = $hsl->withHue(180); // New instance with hue set to 180
$hsl = $hsl->withSaturation(50); // New instance with saturation set to 50
$hsl = $hsl->withLightness(25); // New instance with lightness set to 25

$hex  = $hsl->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX
$rgb  = $hsl->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB
$hsl  = $hsl->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL
$c256 = $hsl->to256(); // Convert the color to \Scriptura\Color\Types\C256

$hsl = $hsl->lighten(10); // New instance that is lightened by 10%
$hsl = $hsl->darken(10); // New instance that is darkened by 10%

$hsl = $hsl->saturate(10); // New instance that is saturated by 10%
$hsl = $hsl->desaturate(10); // New instance that is desaturated by 10%

$mix = $hsl->mix(new \Scriptura\Color\Types\HSL(120, 100, 50)); // Get a new color that is a mix between two colors
```

#### Default template

[](#default-template-2)

`{hue}° {saturation}% {lightness}%`

### 256

[](#256)

> *Terminal 256-color*`000 - 007`: standard colors `008 - 015`: high intensity colors `016 - 231`: 216 colors `232 - 255`: grayscale (black to white) [https://en.wikipedia.org/wiki/ANSI\_escape\_code#Colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)

```
$c256 = new \Scriptura\Color\Types\C256(196); // New 256 color
$c256 = new \Scriptura\Color\Types\C256(196, '{code}'); // New 256 color with template
echo $c256->code(); // 196
echo $c256; // '196'
echo $c256->withTemplate('\e[48;{code}m'); // '\e[48;196m'

$hex  = $c256->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX
$rgb  = $c256->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB
$hsl  = $c256->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL
$c256 = $c256->to256(); // Convert the color to \Scriptura\Color\Types\C256
```

#### Default template

[](#default-template-3)

`{code}`

Change log
----------

[](#change-log)

Please see \[CHANGELOG\]\[link-changelog\] for more information what has changed recently.

Testing
-------

[](#testing)

The test suite can be run with the following composer script.

```
$ composer test
```

Contributing and Forking
------------------------

[](#contributing-and-forking)

Please note that this project is licensed under the MIT license. We encourage forking of this project, but ask that you keep all copyright, attribution notices, and continue to use the [MIT license](/LICENSE.md) in your fork of the project.

For further details on Contributing guidelines, please read the [contributing guide](/CONTRIBUTING.md).

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Martin Dilling-Hansen](https://github.com/martindilling)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](/LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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

Total

4

Last Release

3624d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/58a08b906afaef2d8891c0195c6ce4454d359854d2f0e126ff204cd02d158876?d=identicon)[martindilling](/maintainers/martindilling)

---

Top Contributors

[![martindilling](https://avatars.githubusercontent.com/u/1018838?v=4)](https://github.com/martindilling "martindilling (5 commits)")

---

Tags

colorrgbhexhslterminal color

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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.9M25](/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)
