public function getColors($format = \Pop\Image\Imagick::HEX)
{
// Initialize the colors array and the image resource.
$colors = array();
// Loop through each pixel of the image, recording the color result
// in the color array.
for ($h = 0; $h < $this->height; $h++) {
for ($w = 0; $w < $this->width; $w++) {
$point = $this->resource->getImagePixelColor($w, $h);
$color = $point->getColor();
// Convert to the proper HEX or RGB format.
if ($format) {
$rgb = sprintf('%02s', dechex($color['r'])) . sprintf('%02s', dechex($color['g'])) . sprintf('%02s', dechex($color['b']));
} else {
$rgb = $color['r'] . "," . $color['g'] . "," . $color['b'];
}
// If the color is not already in the array, add to it.
if (!in_array($rgb, $colors)) {
$colors[] = $rgb;
}
}
}
// Return the colors array.
return $colors;
}