PHPackages                             c4n4r/pigment-php - 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. c4n4r/pigment-php

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

c4n4r/pigment-php
=================

A PHP library to generate CSS gradients

1.1.1(2y ago)178MITPHPPHP ^8.1

Since Aug 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/c4n4r/Pigment)[ Packagist](https://packagist.org/packages/c4n4r/pigment-php)[ RSS](/packages/c4n4r-pigment-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Pigment - A simple PHP library for color generation and manipulation
====================================================================

[](#pigment---a-simple-php-library-for-color-generation-and-manipulation)

Pigment is a simple PHP library for color generation and manipulation. It can be used to generate gradients from two hexadecimal sources. It can also be used to manipulate colors (e.g. to make them lighter or darker).

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

[](#installation)

You can install this library via [Composer](https://getcomposer.org/):

```
composer require c4n4r/pigment
```

Usage
-----

[](#usage)

### Create a pigment instance

[](#create-a-pigment-instance)

```
use Pigment\Pigment;
$pigment = new Pigment('#ff0000');

//or generate a random color

$pigment = Pigment::random();

$pigment->getHex(); // #ff0000
$pigment->getRgb(); // ["red" => 255, "green" => 0, "blue" => 0]
```

### Darken or lighten a color

[](#darken-or-lighten-a-color)

```
use Pigment\Pigment;

//darken by 10%
$pigment = new Pigment('#007D64');
$pigment->darken(10); //#00715a

//lighten by 10%
$pigment = new Pigment('#007D64');
$pigment->lighten(10); //#008a6e
```

### You can also generate a gradient between two colors

[](#you-can-also-generate-a-gradient-between-two-colors)

```
use Pigment\Pigment;
$colorOne = new Pigment('#007D64');
$colorTwo = new Pigment('#ff0000');

//create a gradient with 10 steps
$gradient = $colorOne->gradient($colorTwo, 10);
```

Every method that manipulates a color returns a new Pigment class instance.

### Use methods directly from the PigmentColorHandler class

[](#use-methods-directly-from-the-pigmentcolorhandler-class)

```
use Pigment\Handlers\PigmentColorHandler;

$colorHandler = new PigmentColorHandler();

//darken by 10%
$darkenedColor = $colorHandler->darken('#007D64', 25);
$lightenedColor = $colorHandler->lighten('#007D64', 25);

//create a gradient with 10 steps
$gradient = $colorHandler->createGradientBetweenToColors('#007D64', '#ff0000', 10);
```

Those methods do not return a new Pigment class instance, you can use them if you don't need to manipulate the color further.

### Transform colors in different formats

[](#transform-colors-in-different-formats)

You can use the ColorTransformer class to transform colors in different formats without using a Pigment class.

```
$colorTransformer = new ColorTransformer();

//hex to rgb
$colorTransformer->explodeToRgb('#007D64');

//rgb to hex
$colorTransformer->implodeToHex([0, 125, 100]);

//rgb to hsl
$colorTransformer->rgbToHsl([0, 125, 100]);

//hsl to rgb
$colorTransformer->hslToRgb();
```

### Examples

[](#examples)

you can refer to the examples folder for more examples.

License
-------

[](#license)

This library is licensed under the MIT license.

Credits
-------

[](#credits)

This library is developed by Hadrien Delphin, feel free to contact me if you have any question.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Total

3

Last Release

876d ago

PHP version history (2 changes)1.0.0PHP ^8.0

1.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7651d25f0513fd2d31de8d51c53893679a8b246033489de0dde06cc136cd0ca4?d=identicon)[c4n4r](/maintainers/c4n4r)

---

Top Contributors

[![c4n4r](https://avatars.githubusercontent.com/u/9746558?v=4)](https://github.com/c4n4r "c4n4r (27 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/c4n4r-pigment-php/health.svg)

```
[![Health](https://phpackages.com/badges/c4n4r-pigment-php/health.svg)](https://phpackages.com/packages/c4n4r-pigment-php)
```

PHPackages © 2026

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