mauriciourrego/colorcube-php

Dominant color extraction from RGB images — PHP port of Ole Krause-Sparman's algorithm.

v1.0.0 2023-07-28 15:57 UTC

This package is auto-updated.

Last update: 2025-06-28 20:08:10 UTC


README

composer require mauriciourrego/colorcube-php

colorcube-php

Dominant color extraction from RGB images — PHP port of Ole Krause-Sparman's algorithm.

Demo

This is a PHP port of ColorCube, by Ole Krause-Sparmann. You can find an excellent description of how it works at that repo.

ColorCube is for dominant color extraction from RGB images. Given an image element, it returns a sorted array of hex colors.

Usage

$cc = new ColorCube( // all arguments are optional; these are the defaults:
  20,   // color-space resolution
  [255, 255, 255], // avoid color
  0.4,   // distinctness threshold
  0.2,  // brightness threshold
);
$image = imagecreatefromjpeg($image_url);
$colors = $cc->get_colors($image);