<?php 
        $handle = imagick_readimage( getcwd() . "/image.jpg" ) ;
        if ( imagick_iserror( $handle ) )
        {
                $reason      = imagick_failedreason( $handle ) ;
                $description = imagick_faileddescription( $handle ) ;

                print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;
        exit ;
        }

    //
    //  If you want a histogram of the color distribution written to a
    //  file, specify the file name as the second parameter.
    //

    $numb_colors = imagick_getnumbercolors( $handle, "/dev/null" ) ;
    if ( imagick_iserror( $handle ) )
    {
                $reason      = imagick_failedreason( $handle ) ;
                $description = imagick_faileddescription( $handle ) ;

                print "imagick_getnumbercolors failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;
        exit ;
    }

    print "Number of colors: $numb_colors<BR>\n" ;
?>