Image Color Dominator

Dependency: IMagick PHP extension, PHP 5.3+ ImgColorDominator Dependency: Image Magick command line cools, PHP 5.3+ CMDImgColorDominator

A PHP class that tries to pick a nice three color palette (background + 2 color highlights) from an input image with IMagick. (or collection of pixels you've gathered yourself if you're up for it.)

Note: I haven't tested this with transparent images at the time of writing.

A simple example of use:

include 'imgcolordominator.php';
$icd = new ImgColorDominator();
list($bg, $highlight, $sub) = $icd->get_palette();

//This makes modified LAB arrays into CSS color declarations.
$bg = $icd->lab_to_css($bg);
$highlight = $icd->lab_to_css($highlight);
$sub = $icd->lab_to_css($sub);

This will use the (somewhat slow) default settings. You can speed up the process by setting the highlight_scale_w and highlight_scale_h properties lower.

NOTE: Old version used YUV, new version uses a modified LAB colorspace. To get proper CIELab colorspace multiply output each dimension by 100.