CImage.php
private function colorsTotal($im)
    {
        if (imageistruecolor($im)) {
            $this->log("Colors as true color.");
            $h = imagesy($im);
            $w = imagesx($im);
            $c = array();
            for ($x=0; $x < $w; $x++) {
                for ($y=0; $y < $h; $y++) {
                    @$c['c'.imagecolorat($im, $x, $y)]++;
                }
            }
            return count($c);
        } else {
            $this->log("Colors as palette.");
            return imagecolorstotal($im);
        }
    }
private function colorsTotal($im)
    {
        if (imageistruecolor($im)) {
            $this->log("Colors as true color.");
            $h = imagesy($im);
            $w = imagesx($im);
            $c = array();
            for ($x=0; $x < $w; $x++) {
                for ($y=0; $y < $h; $y++) {
                    @$c['c'.imagecolorat($im, $x, $y)]++;
                }
            }
            return count($c);
        } else {
            $this->log("Colors as palette.");
            return imagecolorstotal($im);
        }
    }
private function colorsTotal ( $ im ) { if ( imageistruecolor ( $ im ) ) { $ this -> log ( "Colors as true color." ) ; $ h = imagesy ( $ im ) ; $ w = imagesx ( $ im ) ; $ c = array ( ) ; for ( $ x = 0 ; $ x < $ w ; $ x ++ ) { for ( $ y = 0 ; $ y < $ h ; $ y ++ ) { @ $ c [ 'c' . imagecolorat ( $ im , $ x , $ y ) ] ++ ; } } return count ( $ c ) ; } else { $ this -> log ( "Colors as palette." ) ; return imagecolorstotal ( $ im ) ; } }
Calculate number of colors in an image.

@param resource $im the image.

@return int
Calculate number of colors in an image .