PHPackages                             xetaio/color-extractor - 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. [Image &amp; Media](/categories/media)
4. /
5. xetaio/color-extractor

ActiveLibrary[Image &amp; Media](/categories/media)

xetaio/color-extractor
======================

Extract colors from an image as a human would do.

0.3.3(4y ago)01.7kMITPHPPHP &gt;=5.4.0

Since Aug 8Pushed 4y agoCompare

[ Source](https://github.com/XetaIO/color-extractor)[ Packagist](https://packagist.org/packages/xetaio/color-extractor)[ Docs](https://github.com/thephpleague/color-extractor)[ RSS](/packages/xetaio-color-extractor/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (2)Versions (17)Used By (0)

ColorExtractor
==============

[](#colorextractor)

[![Build Status](https://camo.githubusercontent.com/52b8657bd8f366af07ef9a6f03c9498b884e30e079ad899aa135958085c87b98/68747470733a2f2f7472617669732d63692e6f72672f7468657068706c65616775652f636f6c6f722d657874726163746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/thephpleague/color-extractor)[![Total Downloads](https://camo.githubusercontent.com/b182f8dd9fb4d17f5eab0b50e52e8ff401dfe1d029ef3f09652f6651f6648a3f/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f636f6c6f722d657874726163746f722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/league/color-extractor)[![Latest Stable Version](https://camo.githubusercontent.com/b390f5e95fd901e324dfcb1a40b48f15a394be142875d7108087190be793c74b/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f636f6c6f722d657874726163746f722f762f737461626c652e706e67)](https://packagist.org/packages/league/color-extractor)

Extract colors from an image like a human would do.

Install
-------

[](#install)

Via Composer

```
$ composer require league/color-extractor:0.3.*
```

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';

use League\ColorExtractor\Color;
use League\ColorExtractor\ColorExtractor;
use League\ColorExtractor\Palette;

$palette = Palette::fromFilename('./some/image.png');

// $palette is an iterator on colors sorted by pixel count
foreach($palette as $color => $count) {
    // colors are represented by integers
    echo Color::fromIntToHex($color), ': ', $count, "\n";
}

// it offers some helpers too
$topFive = $palette->getMostUsedColors(5);

$colorCount = count($palette);

$blackCount = $palette->getColorCount(Color::fromHexToInt('#000000'));

// an extractor is built from a palette
$extractor = new ColorExtractor($palette);

// it defines an extract method which return the most “representative” colors
$colors = $extractor->extract(5);
```

Handling transparency
---------------------

[](#handling-transparency)

By default **any pixel with alpha value greater than zero will be discarded**. This is because transparent colors are not perceived as is. For example fully transparent black would be seen white on a white background. So if you want to take transparency into account when building a palette you have to specify this background color. You can do this with the second argument of `Palette` constructors. Its default value is `null`, meaning a color won't be added to the palette if its alpha component exists and is greater than zero.

You can set it as an integer representing the color, then transparent colors will be blended before addition to the palette.

```
// we set a white background so fully transparent colors will be added as white in the palette
// pure red #FF0000 at 50% opacity will be stored as #FF8080 as it would be perceived
$palette = Palette::fromFilename('./some/image.png', Color::fromHexToInt('#FFFFFF'));
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/thephpleague/color-extractor/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Mathieu Lechat](https://github.com/MatTheCat)
- [All Contributors](https://github.com/thephpleague/color-extractor/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/thephpleague/color-extractor/blob/master/LICENSE) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.6% 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 ~225 days

Recently: every ~564 days

Total

15

Last Release

1509d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.3.0

0.2.0PHP &gt;=5.4.0

### Community

Maintainers

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

---

Top Contributors

[![MatTheCat](https://avatars.githubusercontent.com/u/1898254?v=4)](https://github.com/MatTheCat "MatTheCat (46 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![Xety](https://avatars.githubusercontent.com/u/8210023?v=4)](https://github.com/Xety "Xety (2 commits)")[![toin0u](https://avatars.githubusercontent.com/u/672421?v=4)](https://github.com/toin0u "toin0u (1 commits)")[![philsturgeon](https://avatars.githubusercontent.com/u/67381?v=4)](https://github.com/philsturgeon "philsturgeon (1 commits)")[![curtisgibby](https://avatars.githubusercontent.com/u/1086964?v=4)](https://github.com/curtisgibby "curtisgibby (1 commits)")[![thinksaydo](https://avatars.githubusercontent.com/u/519600?v=4)](https://github.com/thinksaydo "thinksaydo (1 commits)")

---

Tags

imagecolorextracthumanpalette

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[league/color-extractor

Extract colors from an image as a human would do.

1.3k4.7M18](/packages/league-color-extractor)[ksubileau/color-thief-php

Grabs the dominant color or a representative color palette from an image.

6353.8M38](/packages/ksubileau-color-thief-php)[brianmcdo/image-palette

Extracts colors from an image and generates a color palette against a whitelist of colors.

179209.0k2](/packages/brianmcdo-image-palette)[marijnvdwerf/material-palette

Prominent image colour extraction for PHP

2952.9k](/packages/marijnvdwerf-material-palette)[talesoft/phim

An image and color manipulation and processing library for PHP

2958.2k](/packages/talesoft-phim)[gabrieldarezzo/colorizzar

Change the colors of an image without lose alpha channnel

273.7k](/packages/gabrieldarezzo-colorizzar)

PHPackages © 2026

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