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

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

ksubileau/color-thief-php
=========================

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

v2.0.2(10mo ago)6353.8M—0.6%67[7 issues](https://github.com/ksubileau/color-thief-php/issues)[2 PRs](https://github.com/ksubileau/color-thief-php/pulls)20MITPHPPHP ^7.2|^8.0CI failing

Since May 4Pushed 10mo ago24 watchersCompare

[ Source](https://github.com/ksubileau/color-thief-php)[ Packagist](https://packagist.org/packages/ksubileau/color-thief-php)[ Docs](http://www.kevinsubileau.fr/projets/color-thief-php)[ RSS](/packages/ksubileau-color-thief-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (11)Used By (20)

Color Thief PHP
===============

[](#color-thief-php)

[![Latest Stable Version](https://camo.githubusercontent.com/3d3120f04fefa774b02964b5037ae7aad2fd4ab0cfcdfadc50f31c0e04579949/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b737562696c6561752f636f6c6f722d74686965662d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ksubileau/color-thief-php)[![Build Status](https://camo.githubusercontent.com/4c73e2d1f58f267f0838ceedf7e9314a2a73f781b7ce685e360ba6b152afb05a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b737562696c6561752f636f6c6f722d74686965662d7068702f74657374732e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/ksubileau/color-thief-php/actions?query=workflow%3ATests)[![GitHub issues](https://camo.githubusercontent.com/aa240f6e218da01513d5e4b9e0802a00d6d1dc716c43dff7e8c91423e615e558/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6b737562696c6561752f636f6c6f722d74686965662d7068703f7374796c653d666c61742d737175617265)](https://github.com/ksubileau/color-thief-php/issues)[![Packagist](https://camo.githubusercontent.com/9323f7498b401b5000e621b3eb3986de874e5195e9dd72f7dae2a689a8308f67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6b737562696c6561752f636f6c6f722d74686965662d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ksubileau/color-thief-php)[![License](https://camo.githubusercontent.com/2974b4ae4b64e2165037236e38b9263b94bd206da3072e03a6c567bf9159a062/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b737562696c6561752f636f6c6f722d74686965662d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ksubileau/color-thief-php)

A PHP class for **grabbing the color palette** from an image. Uses PHP and GD, Imagick or Gmagick libraries to make it happen.

It's a PHP port of the [Color Thief Javascript library](http://github.com/lokesh/color-thief), using the MMCQ (modified median cut quantization) algorithm from the [Leptonica library](http://www.leptonica.com/).

[**See examples**](http://www.kevinsubileau.fr/projets/color-thief-php?utm_campaign=github&utm_term=color-thief-php_readme)

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

[](#requirements)

- PHP &gt;= 7.2 or &gt;= PHP 8.0
- Fileinfo extension
- One or more PHP extensions for image processing:
    - GD &gt;= 2.0
    - Imagick &gt;= 2.0 (but &gt;= 3.0 for CMYK images)
    - Gmagick &gt;= 1.0
- Supports JPEG, PNG, GIF and WEBP images.

How to use
----------

[](#how-to-use)

### Install via Composer

[](#install-via-composer)

The recommended way to install Color Thief is through [Composer](http://getcomposer.org):

```
composer require ksubileau/color-thief-php
```

### Get the dominant color from an image

[](#get-the-dominant-color-from-an-image)

```
require_once 'vendor/autoload.php';
use ColorThief\ColorThief;
$dominantColor = ColorThief::getColor($sourceImage);
```

The `$sourceImage` variable must contain either the absolute path of the image on the server, a URL to the image, a GD resource containing the image, an [Imagick](http://www.php.net/manual/en/class.imagick.php) image instance, a [Gmagick](http://www.php.net/manual/en/class.gmagick.php) image instance, or an image in binary string format.

```
ColorThief::getColor($sourceImage[, $quality=10, $area=null, $outputFormat='array', $adapter = null])
```

You can pass an additional argument (`$quality`) to adjust the calculation accuracy of the dominant color. 1 is the highest quality settings, 10 is the default. But be aware that there is a trade-off between quality and speed/memory consumption ! If the quality settings are too high (close to 1) relative to the image size (pixel counts), it may **exceed the memory limit** set in the PHP configuration (and computation will be slow).

You can also pass another additional argument (`$area`) to specify a rectangular area in the image in order to get dominant colors only inside this area. This argument must be an associative array with the following keys :

- `$area['x']` : The x-coordinate of the top left corner of the area. Default to 0.
- `$area['y']` : The y-coordinate of the top left corner of the area. Default to 0.
- `$area['w']` : The width of the area. Default to the width of the image minus x-coordinate.
- `$area['h']` : The height of the area. Default to the height of the image minus y-coordinate.

By default, color is returned as an array of three integers representing red, green, and blue values. You can choose another output format by passing one of the following values to the `$outputFormat` argument :

- `rgb` : RGB string notation (ex: `rgb(253, 42, 152)`).
- `hex` : String of the hexadecimal representation (ex: `#fd2a98`).
- `int` : Integer color value (ex: `16591512`).
- `array` : Default format (ex: `array[253, 42, 152]`).
- `obj` : Instance of `ColorThief\Color`, for custom processing.

The optional `$adapter` argument lets you choose a preferred image adapter to use to load the image. By default, the adapter is automatically chosen based on the available extensions and the type of `$sourceImage`(e.g. Imagick is used if `$sourceImage` is an Imagick instance). You can pass one of the `Imagick`, `Gmagick` or `Gd` string to force the use of the corresponding underlying image extension. For advanced usage, you can even pass an instance of any class implementing the `AdapterInterface` interface to use a custom image loader.

### Build a color palette from an image

[](#build-a-color-palette-from-an-image)

In this example, we build an 8 color palette.

```
require_once 'vendor/autoload.php';
use ColorThief\ColorThief;
$palette = ColorThief::getPalette($sourceImage, 8);
```

Again, the `$sourceImage` variable must contain either the absolute path of the image on the server, a URL to the image, a GD resource containing the image, an [Imagick](http://www.php.net/manual/en/class.imagick.php) image instance, a [Gmagick](http://www.php.net/manual/en/class.gmagick.php) image instance, or an image in binary string format.

```
ColorThief::getPalette($sourceImage[, $colorCount=10, $quality=10, $area=null, $outputFormat='array', $adapter = null])
```

The `$colorCount` argument determines the size of the palette; the number of colors returned. If not set, it defaults to 10.

The `$quality`, `$area`, `$outputFormat` and `$adapter` arguments work as in the previous function.

Credits
-------

[](#credits)

### Author

[](#author)

by Kevin Subileau [kevinsubileau.fr](http://www.kevinsubileau.fr/?utm_campaign=github&utm_term=color-thief-php_readme)

Based on the fabulous work done by Lokesh Dhakar [lokeshdhakar.com](http://www.lokeshdhakar.com)[twitter.com/lokesh](http://twitter.com/lokesh)

### Thanks

[](#thanks)

- Lokesh Dhakar - For creating the [original project](http://github.com/lokesh/color-thief).
- Nick Rabinowitz - For creating quantize.js.

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance54

Moderate activity, may be stable

Popularity65

Solid adoption and visibility

Community41

Growing community involvement

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 73.9% 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 ~454 days

Recently: every ~628 days

Total

10

Last Release

305d ago

Major Versions

v1.4.1 → v2.0.02022-03-12

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

v1.4.0PHP &gt;=5.4.0

v2.0.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a117de8a64be55f321ccc90875f969cf990b0c0ca4360be4e181d56d3601c89?d=identicon)[ksubileau](/maintainers/ksubileau)

---

Top Contributors

[![ksubileau](https://avatars.githubusercontent.com/u/3837104?v=4)](https://github.com/ksubileau "ksubileau (184 commits)")[![crishoj](https://avatars.githubusercontent.com/u/20393?v=4)](https://github.com/crishoj "crishoj (26 commits)")[![kisPocok](https://avatars.githubusercontent.com/u/434719?v=4)](https://github.com/kisPocok "kisPocok (13 commits)")[![mreiden](https://avatars.githubusercontent.com/u/6321246?v=4)](https://github.com/mreiden "mreiden (9 commits)")[![jbboehr](https://avatars.githubusercontent.com/u/225601?v=4)](https://github.com/jbboehr "jbboehr (4 commits)")[![rewmike](https://avatars.githubusercontent.com/u/294947?v=4)](https://github.com/rewmike "rewmike (4 commits)")[![red-led](https://avatars.githubusercontent.com/u/1540305?v=4)](https://github.com/red-led "red-led (2 commits)")[![simonschaufi](https://avatars.githubusercontent.com/u/941794?v=4)](https://github.com/simonschaufi "simonschaufi (1 commits)")[![furey](https://avatars.githubusercontent.com/u/1914481?v=4)](https://github.com/furey "furey (1 commits)")[![grachov](https://avatars.githubusercontent.com/u/798245?v=4)](https://github.com/grachov "grachov (1 commits)")[![Moerlin](https://avatars.githubusercontent.com/u/5207329?v=4)](https://github.com/Moerlin "Moerlin (1 commits)")[![othmar52](https://avatars.githubusercontent.com/u/7056051?v=4)](https://github.com/othmar52 "othmar52 (1 commits)")[![Redominus](https://avatars.githubusercontent.com/u/22024214?v=4)](https://github.com/Redominus "Redominus (1 commits)")[![chellem](https://avatars.githubusercontent.com/u/570856?v=4)](https://github.com/chellem "chellem (1 commits)")

---

Tags

color-palettedominant-colorsgdimage-processingimagickphpphpcolorpalettethiefdominant

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ksubileau-color-thief-php/health.svg)

```
[![Health](https://phpackages.com/badges/ksubileau-color-thief-php/health.svg)](https://phpackages.com/packages/ksubileau-color-thief-php)
```

###  Alternatives

[league/color-extractor

Extract colors from an image as a human would do.

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

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

179209.0k2](/packages/brianmcdo-image-palette)[dereuromark/media-embed

A PHP library to deal with all those media services around, parsing their URLs and embedding their audio/video content in websites.

182530.3k11](/packages/dereuromark-media-embed)[marijnvdwerf/material-palette

Prominent image colour extraction for PHP

2952.9k](/packages/marijnvdwerf-material-palette)[automattic/wistia-php

PHP wrapper for Wistia API

1431.9k](/packages/automattic-wistia-php)

PHPackages © 2026

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