Skip to content
brianhaveri edited this page Sep 14, 2010 · 9 revisions

List of color methods and parameters

Method Description Parameter Returns
color Get a single color string $hex OR array $query array
colors Get multiple colors array $query array
colors_top Get top colors array $query array
colors_new Get new colors array $query array
colors_random Get random clors [none] array

For color methods, the parameter $query array can include the following keys:

  • format
  • jsonCallback
  • lover – Not available for color()
  • hueRange – Not available for color()
  • briRange – Not available for color()
  • keywords – Not available for color()
  • keywordExact – Not available for color()
  • orderCol – Not available for color()
  • sortBy – Not available for color()
  • numResults – Not available for color()
  • resultOffset – Not available for color()

More information on $query keys and return values at the ColourLOVERS.com API page

Sample Code: Query a single color

// Single color: simple query
require_once('ColourLovers.php');
$c = new ColourLovers;
$simple_result = $c->color('FF0000');
print_r($simple_result);
/*
Array
(
    [@attributes] => Array
        (
            [numResults] => 1
            [totalResults] => 1
        )
    [color] => Array
        (
            [id] => 176
            [title] => Red
            [userName] => kira
            [numViews] => 17664
            [numVotes] => 3
            [numComments] => 127
            [numHearts] => 5
            [rank] => 50
            [dateCreated] => 2005-01-07 20:46:44
            [hex] => FF0000
            [rgb] => Array
                (
                    [red] => 255
                    [green] => 0
                    [blue] => 0
                )
            [hsv] => Array
                (
                    [hue] => 0
                    [saturation] => 100
                    [value] => 100
                )
            [description] => 
            [url] => http://www.colourlovers.com/color/FF0000/Red
            [imageUrl] => http://www.colourlovers.com/img/FF0000/100/100/Red.png
            [badgeUrl] => http://www.colourlovers.com/images/badges/c/0/176_Red.png
            [apiUrl] => http://www.colourlovers.com/api/color/FF0000
        )
)
*/
// Single color: advanced query
require_once('ColourLovers.php');
$c = new ColourLovers;
$advanced_result = $c->color(array('hex'=>'0099FF', 'format'=>'json'));
print_r($advanced_result);
// Results structure matches structure of $simple_result in previous example

Sample Code: Query multiple colors

require_once('ColourLovers.php');
$c = new ColourLovers;
$results = $c->colors(array(
	'keywords'	=> 'sky+cloud',
	'orderCol'	=> 'numVotes',
	'sortBy'	=> 'ASC'
));
print_r($results);
Clone this wiki locally