PHPackages                             totalcms/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. totalcms/color-thief-php

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

totalcms/color-thief-php
========================

Maintained fork of ksubileau/color-thief-php with PHP 8.2+ deprecation fixes. Temporary bridge for Total CMS until the upstream 3.0 release.

v2.5.0(1mo ago)0127↑100%MITPHPPHP ^8.2

Since May 4Pushed 1mo agoCompare

[ Source](https://github.com/totalcms/color-thief-php)[ Packagist](https://packagist.org/packages/totalcms/color-thief-php)[ Docs](https://github.com/totalcms/color-thief-php)[ RSS](/packages/totalcms-color-thief-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (5)Versions (13)Used By (0)

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

[](#color-thief-php)

> **⚠️ This is a maintained fork, not the original package.**`totalcms/color-thief-php` is a temporary fork of [`ksubileau/color-thief-php`](https://github.com/ksubileau/color-thief-php)carrying PHP 8.2+ deprecation fixes that haven't shipped in an upstream stable release yet. It exists solely as a bridge for [Total CMS](https://totalcms.co)until upstream's **3.0** release lands and is verified, at which point this fork will be retired in favour of the upstream package. New projects should depend on the upstream package directly.

[![Latest Stable Version](https://camo.githubusercontent.com/e88263fbca2356373968deb677e3f0e1d8e7072ac4c5f737b1e5d08e4f49ef04/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f74616c636d732f636f6c6f722d74686965662d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/totalcms/color-thief-php)[![Build Status](https://camo.githubusercontent.com/1d40f73a1dbdfc2df3a17ff60d3a11936653141fbbed128e57afbc13799b1027/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f74616c636d732f636f6c6f722d74686965662d7068702f74657374732e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/totalcms/color-thief-php/actions?query=workflow%3ATests)[![GitHub issues](https://camo.githubusercontent.com/400203a66b80ca585078d710104c1ac8affef91e204cf171e7706eaead43ff81/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f746f74616c636d732f636f6c6f722d74686965662d7068703f7374796c653d666c61742d737175617265)](https://github.com/totalcms/color-thief-php/issues)[![License](https://camo.githubusercontent.com/a29cf0b5defb444aaa8d72c717d974ca787be8b98a194ca5a60f00dde0631b5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f74616c636d732f636f6c6f722d74686965662d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/totalcms/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 totalcms/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)

### Fork maintainer

[](#fork-maintainer)

This fork is maintained by [Joe Workman](https://totalcms.co) for [Total CMS](https://totalcms.co).

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

54

—

FairBetter than 97% of packages

Maintenance89

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 67.4% 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 ~440 days

Recently: every ~693 days

Total

11

Last Release

55d ago

Major Versions

v1.4.1 → v2.0.02022-03-12

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

v1.4.0PHP &gt;=5.4.0

v2.0.0PHP ^7.2|^8.0

v2.5.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/225628?v=4)[Joe Workman](/maintainers/joeworkman)[@joeworkman](https://github.com/joeworkman)

---

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)")[![joeworkman](https://avatars.githubusercontent.com/u/225628?v=4)](https://github.com/joeworkman "joeworkman (24 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

phpcolorpalettethiefdominant

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[ksubileau/color-thief-php

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

6394.1M46](/packages/ksubileau-color-thief-php)[league/color-extractor

Extract colors from an image as a human would do.

1.3k5.1M20](/packages/league-color-extractor)[brianmcdo/image-palette

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

179222.1k3](/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.

181576.2k17](/packages/dereuromark-media-embed)[marijnvdwerf/material-palette

Prominent image colour extraction for PHP

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

PHPackages © 2026

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