PHPackages                             rasim/image-palette - 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. rasim/image-palette

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

rasim/image-palette
===================

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

v2.0.1(10y ago)07.6kMITPHPPHP &gt;=5.4.0

Since Jan 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/RaSiM/ImagePalette)[ Packagist](https://packagist.org/packages/rasim/image-palette)[ Docs](https://github.com/BrianMcdo/ImagePalette)[ RSS](/packages/rasim-image-palette/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

ImagePalette
============

[](#imagepalette)

[![Build Status](https://camo.githubusercontent.com/c6a100a16e1033d6613647fa6c3103e8b3b63014cd171d979c380e1b37745bf4/68747470733a2f2f7472617669732d63692e6f72672f627269616e6d63646f2f496d61676550616c657474652e706e67)](https://travis-ci.org/brianmcdo/ImagePalette)[![Total Downloads](https://camo.githubusercontent.com/b20702ad174162d74ff9e17c75abed3dcecc8c9fd2fa8d3953b563d7df7bcf4a/68747470733a2f2f706f7365722e707567782e6f72672f627269616e6d63646f2f696d6167652d70616c657474652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/brianmcdo/image-palette)[![Latest Stable Version](https://camo.githubusercontent.com/2a89b40332e79b5b9a526f204b8558975c4efc77ce5525f1af27888073b18336/68747470733a2f2f706f7365722e707567782e6f72672f627269616e6d63646f2f696d6167652d70616c657474652f762f737461626c652e706e67)](https://packagist.org/packages/brianmcdo/image-palette)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/290dc276b93bc4939f1d416ce94be96496a7301b0eceadb52e3cbc70a7f6885c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f627269616e6d63646f2f496d61676550616c657474652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/brianmcdo/ImagePalette/?branch=master)

ImagePalette is used to extract a color palette from a given image. Aside from being a native PHP implementation, ImagePalette differs from many palette extractors as it works off a white list color palette. Below is the default palette:

[![](https://camo.githubusercontent.com/a01130603e89bc56412b9f74dd747c691bfbf1063f0f956fe532821b861825f7/687474703a2f2f692e696d6775722e636f6d2f526162716b71712e706e67)](https://camo.githubusercontent.com/a01130603e89bc56412b9f74dd747c691bfbf1063f0f956fe532821b861825f7/687474703a2f2f692e696d6775722e636f6d2f526162716b71712e706e67)

The main advantage of working from a color palette is closer matching, as each pixel simply has to calculate the color-distance within the palette and chose the best match. This is useful for working with color taxonomies as the taxonomy should have a finite amount of colors.

[![](https://camo.githubusercontent.com/a67de34b7c70d9df87a747082d4a55efbc4a9df19e7d9f3a75658b94e4736b8c/687474703a2f2f692e696d6775722e636f6d2f4f38667346577a2e706e67)](https://camo.githubusercontent.com/a67de34b7c70d9df87a747082d4a55efbc4a9df19e7d9f3a75658b94e4736b8c/687474703a2f2f692e696d6775722e636f6d2f4f38667346577a2e706e67)

See an example of this in action here:

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

[](#requirements)

`PHP >= 5.4` `php5-gd`

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

[](#installation)

Simply add the following to your `composer.json` file:

```
"require": {
    "brianmcdo/image-palette": "dev-master"
}
```

Usage
-----

[](#usage)

```
// initiate with image
$palette = new \BrianMcdo\ImagePalette\ImagePalette( 'https://www.google.co.uk/images/srpr/logo3w.png' );

// get the prominent colors
$colors = $palette->colors; // array of Color objects

// to string as json
echo $palette; // '["#ffffdd", ... ]'

// implements IteratorAggregate
foreach ($palette as $color) {
  // Color provides several getters/properties
  echo $color;             // '#ffffdd'
  echo $color->rgbString;  // 'rgb(255,255,221)'
  echo $color->rgbaString; // 'rgba(255,255,221,0.25)'
  echo $color->int;        // 0xffffdd
  echo $color->rgb;        // array(255,255,221)
  echo $color->rgba;       // array(255,255,221,0.25)
  // ...
}
```

And there we go!

### Laravel 4

[](#laravel-4)

Find the `providers` key in `app/config/app.php` and register the `ImagePaletteServiceProvider`:

```
'providers' => array(
    // ...
    'BrianMcdo\ImagePalette\Laravel\ImagePaletteServiceProvider',
)
```

Then, find the `aliases` key in `app/config/app.php` and register the `ImagePaletteFacade`:

```
'aliases' => array(
    // ...
    'ImagePalette' => 'BrianMcdo\ImagePalette\Laravel\ImagePaletteFacade',
)
```

Example:

```
$fileOrUrl = 'https://www.google.com/images/srpr/logo11w.png';

ImagePalette::getColors($fileOrUrl);
```

### Options

[](#options)

#### Precision

[](#precision)

By default, `ImagePalette` will process every 10th pixel. This is for performance reasons, you can change this like below. The precision is a performance-to-time decision.

```
$palette = new \BrianMcdo\ImagePalette\ImagePalette( $src, 5 /* precision */ );
```

#### Color Count

[](#color-count)

To control the amount colors returned set the third parameter. You can also provide the getter with a custom length.

```
$palette = new \BrianMcdo\ImagePalette\ImagePalette( $src, 5, 3 /* number of colors to return */ );
$colors = $palette->getColors(7 /* number of colors to return */);
```

Contribution guidelines
-----------------------

[](#contribution-guidelines)

See:

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 68.5% 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 ~327 days

Total

3

Last Release

3851d ago

Major Versions

v1.0 → v2.02014-10-08

PHP version history (2 changes)v1.0PHP &gt;=5.3.0

v2.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a96f19c173953360c6205f60956dbd31c5c30c1f7592ceb8fe238bfe26ea45c?d=identicon)[RaSiM](/maintainers/RaSiM)

---

Top Contributors

[![brianmcdo](https://avatars.githubusercontent.com/u/2156475?v=4)](https://github.com/brianmcdo "brianmcdo (100 commits)")[![gandalfx](https://avatars.githubusercontent.com/u/2844390?v=4)](https://github.com/gandalfx "gandalfx (20 commits)")[![joehoyle](https://avatars.githubusercontent.com/u/161683?v=4)](https://github.com/joehoyle "joehoyle (18 commits)")[![rasim](https://avatars.githubusercontent.com/u/983327?v=4)](https://github.com/rasim "rasim (3 commits)")[![richardswain](https://avatars.githubusercontent.com/u/888319?v=4)](https://github.com/richardswain "richardswain (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![bhavyanshu](https://avatars.githubusercontent.com/u/3829459?v=4)](https://github.com/bhavyanshu "bhavyanshu (1 commits)")

---

Tags

laravelimagegdcolorextractorpalette

### Embed Badge

![Health badge](/badges/rasim-image-palette/health.svg)

```
[![Health](https://phpackages.com/badges/rasim-image-palette/health.svg)](https://phpackages.com/packages/rasim-image-palette)
```

###  Alternatives

[brianmcdo/image-palette

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

179209.0k2](/packages/brianmcdo-image-palette)[league/color-extractor

Extract colors from an image as a human would do.

1.3k4.7M18](/packages/league-color-extractor)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M101](/packages/intervention-image-laravel)[talesoft/phim

An image and color manipulation and processing library for PHP

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

Prominent image colour extraction for PHP

2952.9k](/packages/marijnvdwerf-material-palette)

PHPackages © 2026

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