PHPackages                             naomai/php-dominantcolor - 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. naomai/php-dominantcolor

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

naomai/php-dominantcolor
========================

Find dominant colors in an image using K-means clustering

035

Since Jun 12Pushed 5y agoCompare

[ Source](https://github.com/teraxis/php-dominantcolor)[ Packagist](https://packagist.org/packages/naomai/php-dominantcolor)[ RSS](/packages/naomai-php-dominantcolor/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Dominant Color library
==========================

[](#php-dominant-color-library)

This library extracts dominant colors from images - those, which are most likely to attract the viewer's eyes.

[![Album arts example](example/albums.jpg)](example/albums.jpg)

The library uses [K-means clustering](https://en.wikipedia.org/wiki/K-means_clustering) method to group image pixels into different *color bins*. Those colors are then evaluated by their saturation and differences between others. Two of them are picked as *most prominent* (primary and secondary).

Usage
-----

[](#usage)

We want to find most prominent colors with three additional colors from image `heart.png`.

```
$imageSrc = "heart.png";
$totalNumberOfColors = 5; // primary + secondary + 3 additional

$colorInfo = Naomai\DominantColor::fromFile($imageSrc, $totalNumberOfColors);
```

Number of colors is the number of *color bins*, it also should include primary and secondary colors.

The result is an array of following structure:

```
$colorInfo = [
	'primary' => 0xDEFDEF,
	'secondary' => 0xABCABC,
	'palette' => [
		0 => ['color' => 0xABCABC, 'score' => 0.8],
		/// etc
	]
```

All colors are formatted as standard RGB integer in form: `0xRRGGBB`. `palette` contains additional colors. The `score` field is a score from secondary color choosing algorithm. The chosen secondary color has value of `1.0`.

See **examples** directory for a visual demonstration.

This project relies on the elegant [PHP K-Means](https://github.com/bdelespierre/php-kmeans/) library by Benjamin Delespierre.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![naomai](https://avatars.githubusercontent.com/u/9076785?v=4)](https://github.com/naomai "naomai (3 commits)")

### Embed Badge

![Health badge](/badges/naomai-php-dominantcolor/health.svg)

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

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[char0n/ffmpeg-php

PHP wrapper for FFmpeg application

495225.1k1](/packages/char0n-ffmpeg-php)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)

PHPackages © 2026

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