PHPackages                             mexitek/phpcolors - 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. mexitek/phpcolors

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

mexitek/phpcolors
=================

A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

v1.0.4(4y ago)5003.6M—9.8%55[1 issues](https://github.com/mexitek/phpColors/issues)18MITPHPPHP ^7.2|^8.0

Since Sep 19Pushed 3y ago29 watchersCompare

[ Source](https://github.com/mexitek/phpColors)[ Packagist](https://packagist.org/packages/mexitek/phpcolors)[ Docs](http://mexitek.github.com/phpColors/)[ RSS](/packages/mexitek-phpcolors/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (9)Used By (18)

PHPColors [![Build Status](https://camo.githubusercontent.com/e747991d82e87dbe49f4bbd35cdb70d42c09d0c6bd2454fc3825d27567841f9c/68747470733a2f2f7472617669732d63692e6f72672f6d65786974656b2f706870436f6c6f72732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mexitek/phpColors)
============================================================================================================================================================================================================================================================================================

[](#phpcolors-)

> A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

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

[](#requirements)

PHPColors requires PHP version 7.2.0 or greater.

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

[](#installation)

### Composer

[](#composer)

Simply add `mexitek/phpcolors` to `composer.json` using `dev-master`.

```
composer require mexitek/phpcolors:dev-master

```

How it works
------------

[](#how-it-works)

Instantiate an object of the color class with a hex color string `$foo = new Color("336699")`. That's it! Now, call the methods you need for different color variants.

Available Methods
-----------------

[](#available-methods)

- **darken( \[$amount\] )** : Allows you to obtain a darker shade of your color. Optionally you can decide to darken using a desired percentage.
- **lighten( \[$amount\] )** : Allows you to obtain a lighter shade of your color. Optionally you can decide to lighten using a desired percentage.
- **mix($hex, \[$amount\] )** : Allows you to mix another color to your color. Optionally you can decide to set the percent of second color or original color amount is ranged -100...0...100.
- **isLight( \[$hex\] )** : Determins whether your color (or the provide param) is considered a "light" color. Returns `TRUE` if color is light.
- **isDark( \[$hex\] )** : Determins whether your color (or the provide param) is considered a "dark" color. Returns `TRUE` if color is dark.
- **makeGradient( \[$amount\] )** : Returns an array with 2 indices `light` and `dark`, the initial color will either be selected for `light` or `dark` depending on its brightness, then the other color will be generated. The optional param allows for a static lighten or darkened amount.
- **complementary()** : Returns the color "opposite" or complementary to your color.
- **getHex()** : Returns the original hex color.
- **getHsl()** : Returns HSL array for your color.
- **getRgb()** : Returns RGB array for your color.

> Auto lightens/darkens by 10% for sexily-subtle gradients

```
/**
 * Using The Class
 */

use Mexitek\PHPColors\Color;

// Initialize my color
$myBlue = new Color("#336699");

echo $myBlue->darken();
// 1a334d

echo $myBlue->lighten();
// 8cb3d9

echo $myBlue->isLight();
// false

echo $myBlue->isDark();
// true

echo $myBlue->complementary();
// 996633

echo $myBlue->getHex();
// 336699

print_r( $myBlue->getHsl() );
// array( "H"=> 210, "S"=> 0.5, "L"=>0.4 );

print_r( $myBlue->getRgb() );
// array( "R"=> 51, "G"=> 102, "B"=>153 );

print_r($myBlue->makeGradient());
// array( "light"=>"8cb3d9" ,"dark"=>"336699" )
```

Static Methods
--------------

[](#static-methods)

- **hslToHex( $hsl )** : Convert a HSL array to a HEX string.
- **hexToHsl( $hex )** : Convert a HEX string into an HSL array.
- **hexToRgb( $hex )** : Convert a HEX string into an RGB array.
- **rgbToHex( $rgb )** : Convert an RGB array into a HEX string.

```
/**
 * On The Fly Custom Calculations
 */

use Mexitek\PHPColors\Color;

 // Convert my HEX
 $myBlue = Color::hexToHsl("#336699");

 // Get crazy with the HUE
 $myBlue["H"] = 295;

 // Gimme my new color!!
 echo Color::hslToHex($myBlue);
 // 913399
```

CSS Helpers
-----------

[](#css-helpers)

- **getCssGradient( \[$amount\] \[, $vintageBrowsers\] )** : Generates the CSS3 gradients for safari, chrome, opera, firefox and IE10. Optional percentage amount for lighter/darker shade. Optional boolean for older gradient CSS support.

> Would like to add support to custom gradient stops

```
use Mexitek\PHPColors\Color;

// Initialize my color
$myBlue = new Color("#336699");

// Get CSS
echo $myBlue->getCssGradient();
/* - Actual output doesn't have comments and is single line

  // fallback background
  background: #336699;

  // IE Browsers
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8cb3d9', endColorstr='#336699');

  // Safari 5.1+, Mobile Safari, Chrome 10+
  background-image: -webkit-linear-gradient(top, #8cb3d9, #336699);

  // Standards
  background-image: linear-gradient(to bottom, #8cb3d9, #336699);

*/
```

However, if you want to support the ancient browsers (which has negligible market share and almost died out), you can set the second parameter to `TRUE`. This will output:

```
use Mexitek\PHPColors\Color;
$myBlue = new Color("#336699");

// Get CSS
echo $myBlue->getCssGradient(10, TRUE);
/* - Actual output doesn't have comments and is single line

  background: #336699; // fallback background
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8cb3d9', endColorstr='#336699'); // IE Browsers
  background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#8cb3d9), to(#336699)); // Safari 4+, Chrome 1-9
  background-image: -webkit-linear-gradient(top, #8cb3d9, #336699); // Safari 5.1+, Mobile Safari, Chrome 10+
  background-image: -moz-linear-gradient(top, #8cb3d9, #336699); // Firefox 3.6+
  background-image: -o-linear-gradient(top, #8cb3d9, #336699); // Opera 11.10+
  background-image: linear-gradient(to bottom, #8cb3d9, #336699); // Standards

*/
```

Github Contributors
-------------------

[](#github-contributors)

- mexitek
- danielpataki
- alexmglover
- intuxicated
- pborreli
- curtisgibby
- matthewpatterson
- there4
- alex-humphreys
- zaher
- primozcigler
- thedavidmeister
- tylercd100
- Braunson

License
=======

[](#license)

See LICENSE file or [arlo.mit-license.org](http://arlo.mit-license.org)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity64

Solid adoption and visibility

Community41

Growing community involvement

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 69.2% 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 ~479 days

Recently: every ~119 days

Total

8

Last Release

1634d ago

Major Versions

0.5 → 1.02020-08-05

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

1.0PHP ^7.2

v1.0.3PHP ^7.2|^8.0

### Community

Maintainers

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

---

Top Contributors

[![mexitek](https://avatars.githubusercontent.com/u/515706?v=4)](https://github.com/mexitek "mexitek (110 commits)")[![primozcigler](https://avatars.githubusercontent.com/u/4201548?v=4)](https://github.com/primozcigler "primozcigler (7 commits)")[![BIGjuevos](https://avatars.githubusercontent.com/u/1751088?v=4)](https://github.com/BIGjuevos "BIGjuevos (5 commits)")[![mikaykun](https://avatars.githubusercontent.com/u/18062180?v=4)](https://github.com/mikaykun "mikaykun (4 commits)")[![zaher](https://avatars.githubusercontent.com/u/287490?v=4)](https://github.com/zaher "zaher (3 commits)")[![cedric-anne](https://avatars.githubusercontent.com/u/33253653?v=4)](https://github.com/cedric-anne "cedric-anne (3 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (3 commits)")[![sgtlambda](https://avatars.githubusercontent.com/u/5894809?v=4)](https://github.com/sgtlambda "sgtlambda (2 commits)")[![thedavidmeister](https://avatars.githubusercontent.com/u/629710?v=4)](https://github.com/thedavidmeister "thedavidmeister (2 commits)")[![chemix](https://avatars.githubusercontent.com/u/42802?v=4)](https://github.com/chemix "chemix (2 commits)")[![tylercd100](https://avatars.githubusercontent.com/u/4522226?v=4)](https://github.com/tylercd100 "tylercd100 (2 commits)")[![atmattpatt](https://avatars.githubusercontent.com/u/1574315?v=4)](https://github.com/atmattpatt "atmattpatt (2 commits)")[![strarsis](https://avatars.githubusercontent.com/u/9271436?v=4)](https://github.com/strarsis "strarsis (1 commits)")[![theKayani](https://avatars.githubusercontent.com/u/5862564?v=4)](https://github.com/theKayani "theKayani (1 commits)")[![mikehayesuk](https://avatars.githubusercontent.com/u/591318?v=4)](https://github.com/mikehayesuk "mikehayesuk (1 commits)")[![alexmglover](https://avatars.githubusercontent.com/u/375765?v=4)](https://github.com/alexmglover "alexmglover (1 commits)")[![Braunson](https://avatars.githubusercontent.com/u/577273?v=4)](https://github.com/Braunson "Braunson (1 commits)")[![curtisgibby](https://avatars.githubusercontent.com/u/1086964?v=4)](https://github.com/curtisgibby "curtisgibby (1 commits)")[![intuxicated](https://avatars.githubusercontent.com/u/1641461?v=4)](https://github.com/intuxicated "intuxicated (1 commits)")[![Jleagle](https://avatars.githubusercontent.com/u/381099?v=4)](https://github.com/Jleagle "Jleagle (1 commits)")

---

Tags

cssuicolordesignfrontend

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mexitek-phpcolors/health.svg)

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

###  Alternatives

[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[scssphp/scssphp

scssphp is a compiler for SCSS written in PHP.

62827.7M220](/packages/scssphp-scssphp)[livewire/flux

The official UI component library for Livewire.

9475.0M86](/packages/livewire-flux)[spatie/color

A little library to handle color conversions

38118.9M28](/packages/spatie-color)[lara-zeus/popover

Zeus Popover is filamentphp component to show a Popover with custom content in tables and infolist

2968.2k3](/packages/lara-zeus-popover)[lara-zeus/inline-chart

Zeus Inline Chart easily add a chart in filamentPHP table column

2139.9k](/packages/lara-zeus-inline-chart)

PHPackages © 2026

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