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

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

phpexperts/color-speaker
========================

An easy-to-use converter for different types of color models.

v1.2.0(1y ago)251[2 issues](https://github.com/phpexpertsinc/ColorSpeaker/issues)MITPHPPHP &gt;=7.4CI failing

Since Jun 12Pushed 1y ago2 watchersCompare

[ Source](https://github.com/phpexpertsinc/ColorSpeaker)[ Packagist](https://packagist.org/packages/phpexperts/color-speaker)[ Docs](https://www.phpexperts.pro/)[ RSS](/packages/phpexperts-color-speaker/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

ColorSpeaker
============

[](#colorspeaker)

[![Travis CI](https://camo.githubusercontent.com/ff0b5958d3bc3a2980dc4c22bff314c07501b12830807e7e88ea1ed04eedd4fd/68747470733a2f2f7472617669732d63692e636f6d2f70687065787065727473696e632f436f6c6f72537065616b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/phpexpertsinc/ColorSpeaker)[![Maintainability](https://camo.githubusercontent.com/a2a527d9a40c03717fe606aac46785e72d51763c51731c39dc5e4ab6cbda3e93/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35303363626130633533656232363263393437612f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpexpertsinc/SimpleDTO/maintainability)[![Maintainability](https://camo.githubusercontent.com/cccdb0944e8f0f44aae7ca2b53b7dcd54b17fde3f921d2eaf4a0bad2080630de/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31646666396530386635343531366334316534642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpexpertsinc/ColorSpeaker/maintainability)[![Test Coverage](https://camo.githubusercontent.com/a29de01961ddb8bb13d93c15312e89f4354daa6fced6a6e023b8855f68c37518/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31646666396530386635343531366334316534642f746573745f636f766572616765)](https://codeclimate.com/github/phpexpertsinc/ColorSpeaker/test_coverage)

ColorSpeaker is a PHP Experts, Inc., Project is an easy-to-use converter for different types of color models.

It aims to support all major color models: RGB, CSS hex codes, HSL and HSV.

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

[](#installation)

Via Composer

```
composer require phpexperts/color-speaker
```

Usage
-----

[](#usage)

Initialize it with 3 standard RGB integers:

```
$rgbSpeaker = ColorSpeaker::fromRGB(123, 111, 55);
$hexSpeaker = ColorSpeaker::fromHexCode('#7B6F37');
$hslSpeaker = ColorSpeaker::fromHSL(49, 38, 35);
```

It can easily be used as a string for css-compatible output:

```
$csv = ".box { background-color: $rgbSpeaker; }";
// .box { background-color: rgb(123, 111, 55); }
$csvHex = ".box { background-color: $hexSpeaker; }";
// .box { background-color: #7B6F37; }
```

You can also fetch the RGBColor and the HexColor directly:

```
$rgbColor = $rgbSpeaker->toRGB();
/*
   (string) $rgbColor === rgb(123, 111, 55);

   SimpleDTO => {
       'red'   => 123,
       'green' => 111,
       'blue'  => 55
   };
*/
```

See the [**SimpleDTO Project**](https://github.com/phpexpertsinc/simple-dto) for more.

You can also export to different color formats:

```
$hexColor = $rgbSpeaker->toHexCode();
/**
    (string) $hexColor === #7B6F37

    SimpleDTO => {
        'hex' => '#7B6F37
    }
**/
```

All colors serializable and easily converted to JSON objects:

```
$linguist = ColorSpeaker::fromHexCode('#7B6F37');
$rgbColor = $linguist->toRGB();
echo json_encode($rgbColor, JSON_PRETTY_PRINT);
/**
{
    "red": 123,
    "green": 111,
    "blue": 55
}
**/
```

Use cases
=========

[](#use-cases)

PHPExperts\\ColorSpeaker\\ColorSpeaker
✔ Can be constructed from an RGBColor
✔ Can be constructed from a HexColor
✔ Can be constructed from an HSLColor
✔ From RGB: Will only accept integers between 0 and 255, inclusive
✔ From CSS Hex: Will only accept a valid 3 or 6 digit Hex color string, starting with a "#" sign
✔ Can return an RGBColor
✔ Can return a CSSHexColor
✔ Can return an HSLColor
✔ Can be outputted as a CSS string

PHPExperts\\ColorSpeaker\\DTOs\\RGBColor
✔ Will only accept integers between 0 and 255, inclusive
✔ Will only accept literal integers
✔ Can be constructed with a zero-indexed array
✔ Can be outputted as a CSS string

PHPExperts\\ColorSpeaker\\DTOs\\CSSHexColor
✔ Can assert if a string is a valid CSS hex color
✔ The hex code must start with a "#" sign
✔ Will only accept three digit and six digit hex codes
✔ Can be outputted as a CSS string

PHPExperts\\ColorSpeaker\\DTOs\\HSLColor
✔ Will only accept a valid HSL geometry of percentages or percent-integers
✔ Can be constructed with a zero-indexed array
✔ Can be constructed with integers
✔ Can be outputted as a CSS string

Testing
-------

[](#testing)

```
phpunit --testdox
```

Contributors
============

[](#contributors)

[Theodore R. Smith](https://www.phpexperts.pro/%5D)
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.

A **big** shoutout to [https://www.w3schools.com/colors/colors\_converter.asp](https://www.w3schools.com/colors/colors_converter.asp). That *wonderful* color converter made this project's development 70% easier!

License
-------

[](#license)

MIT license. Please see the [license file](LICENSE) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~536 days

Total

6

Last Release

382d ago

Major Versions

v0.50 → v1.0.02019-06-13

PHP version history (3 changes)v0.25PHP &gt;=7.1

v1.1.1PHP &gt;=7.2

v1.2.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f3a2dd16766f6b03c330e65aaca9dfb97f1bbbb41c5e2af5681f58f670b7917?d=identicon)[hopeseekr](/maintainers/hopeseekr)

---

Top Contributors

[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (20 commits)")

---

Tags

rgb colorshtml colorscss colorshex colors

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[lkallas/estonianpin

A simple library for processing Estonian Personal Identification Code (isikukood).

1615.7k](/packages/lkallas-estonianpin)[eve/dto

Simplistic, flexible Data Transfer Object library

1214.8k](/packages/eve-dto)

PHPackages © 2026

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