NAME

App::ColorNamer - Hex to color name converter

SYNOPSIS

use App::ColorNamer;

my $app = App::ColorNamer->new;

my $color = $app->get_name('#aaa')
    or die $app->error;

print "Exact match!\n"
    if $color->{exact};

printf "Color name: %s\nHEX: #%s\nRGB: %s\nHSL: %s\n",
    @$color{ qw/name  hex/ },
    join(', ', @{ $color->{rgb} }{ qw/r g b/ }),
    join(', ', @{ $color->{hsl} }{ qw/h s l/ });

Output:

Color name: Silver Chalice
HEX: #acacac
RGB: 172, 172, 172
HSL: 0, 0, 0.674509803921569

DESCRIPTION

This module ports a useful JavaScript creation by Chirag Mehta (http://chir.ag/projects/name-that-color/) that tells you the name of the color based on its hex RGB value.

METHODS

new

my $app = App::ColorNamer->new;

Returns a freshly baked App::ColorNamer object. Does not take any arguments.

get_name

my $color = $app->get_name('fff', 1);

my $color = $app->get_name('#fff');

my $color = $app->get_name('#ffffff', 1);

my $color = $app->get_name('98ff98')
    or die $app->error;

$VAR1 = {
    'name' => 'Mint Green',
    'hex' => '98ff98'
    'exact' => 1,
    'rgb' => {
        'r' => 152,
        'b' => 152,
        'g' => 255
    },
    'hsl' => {
        'l' => '0.798039215686275',
        'h' => 120,
        's' => 1
    },
};

Takes one mandatory and one optional arguments. The first one is a mandatory hexadecimal 3 or 6-digit color code. The module strips non-hexadecimal characters, so the code can be prefixed by, say, a hash sign. The second argument can be set to either true or false values. If it is set to a true value, the plugin will only use "sane" colors for matching; see sane_colors() method for more info.

If an error occurs, returns undef or empty list, depending on the context, and the error message can be obtained via error() method. On success, returns a hashref with the following keys/values:

exact

{
    'exact' => 1,
...

If this key is present, it will be set to a true value, which is an indication that the provided color code matched one of the colors known to the module exactly. If such match did not occur, module will return the closest match; and exact key will be absent.

name

{
    'name' => 'Mint Green',
...

This key will contain the name of the color that is closest to the color you provided. For a full list of colors known to the module, see known_colors() method.

hex

{
    'hex' => '98ff98'
...

This key will contain six hexadecimal digits representing the color that is closest to the one you provided.

rgb

{
    'rgb' => {
        'r' => 152,
        'b' => 152,
        'g' => 255     
    },
...

This key will contain a hashref with three values that represent RGB (red, green, and blue) values of the matched color. The keys for those values are r, b and g for red, green and blue values respectively. These values will be decimal.

hsl

{
    'hsl' => {
        'l' => '0.798039215686275',
        'h' => 120,
        's' => 1
    },
...

This key is the same as rgb, except this one specifies the HSL (hue, saturation, lightness) values. The keys for the values are h, s and l for hue, saturation and lightness respectively.

error

my $color = $app->get_name('98ff98')
    or die $app->error;

If get_name() method fails, the error will be available as a human readable string returned by error() method.

known_colors

use Data::Dumper;
print Dumper $app->known_colors;

$VAR1 = {
    'rgb' => {
               'r' => 255,
               'b' => 240,
               'g' => 255
             },
    'name' => 'Ivory',
    'hsl' => {
               'l' => '0.970588235294118',
               'h' => 60,
               's' => 1
             },
    'hex' => 'fffff0'
  },
  {
    'rgb' => {
               'r' => 255,
               'b' => 255,
               'g' => 255
             },
    'name' => 'White',
    'hsl' => {
               'l' => 1,
               'h' => 0,
               's' => 0
             },
    'hex' => 'ffffff'
  }
....

Takes no arguments. Returns an arrayref, each element of which is a hashref that represents one known to the plugin color. The format of the hashrefs are the same as of that returned by get_name() method.

sane_colors

my $current_sane_colors = $app->sane_colors;

# adds 'Rose White', 'Baja White', and 'Gin Fizz' to sane colors
push @$current_sane_colors, qw/FFF6F5  FFF8D1  FFF9E2/;
$app->sane_colors( $current_sane_colors );

Returns an arrayref with 6-digit hex codes of colors that the module accredits with "sanity". This means those are the colors that I could imagine when I read the name (see LIST OF SANE COLORS section below). Can be called with one optional argument, which must be an arrayref. When specified, each element of the arrayref must be a hexadecimal code of one of the colors known to the module (see known_colors() method above); and the new list of colors will be the new "sane colors". In other words, these will be the only colors plugin will consider when second argument to get_name() method is set to a true value.

color

my $last_color = $app->color;

Takes no arguments. Must be called only after a successful call to get_name() (see above). Returns the same thing last successful call to get_name() returned.

LIST OF SANE COLORS

This is the list of colors plugin knows to be "sane". The list is rather subjective, and if you feel that some colors need to be added to or removed from this list, feel free to submit a bug.

000000  Black
000080  Navy Blue
0000C8  Dark Blue
0000FF  Blue
008080  Teal
00FF00  Green
00FFFF  Cyan / Aqua
0C0B1D  Ebony
130A06  Asphalt
1560BD  Denim
161D10  Hunter Green
240A40  Violet
242E16  Black Olive
251607  Graphite
262335  Steel Gray
30D5C8  Turquoise
315BA1  Azure
370202  Chocolate
3C2005  Dark Ebony
3C4151  Bright Gray
3F2109  Bronze
3F2500  Cola
4169E1  Royal Blue
41AA78  Ocean Green
4F69C6  Indigo
50C878  Emerald
5F5F6E  Mid Gray
6456B7  Blue Violet
660099  Purple
661010  Dark Tan
66FF00  Bright Green
6B8E23  Olive Drab
6CDAE7  Turquoise Blue
6E7783  Pale Sky
76D7EA  Sky Blue
7A58C1  Fuchsia Blue
808000  Olive
808080  Gray
8B8680  Natural Gray
964B00  Brown
9AC2B8  Shadow Green
A8989B  Dusty Gray
A9A491  Gray Olive
A9ACB6  Aluminium
ABA0D9  Cold Purple
ADDFAD  Moss Green
ADFF2F  Green Yellow
B10000  Bright Red
B57EDC  Lavender
B5B35C  Olive Green
B7410E  Rust
B87333  Copper
BDBBD7  Lavender Gray
BFFF00  Lime
C0C0C0  Silver
C5E17A  Yellow Green
C62D42  Brick Red
C71585  Red Violet
CC5500  Burnt Orange
D2B48C  Tan
D7D0FF  Fog
E0B0FF  Mauve
E0FFFF  Baby Blue
F5F5DC  Beige
F7468A  Violet Red
FDE910  Lemon
FEFCED  Orange White
FF0000  Red
FF00FF  Magenta / Fuchsia
FF3F34  Red Orange
FF681F  Orange
FF69B4  Hot Pink
FFBF00  Amber
FFC0CB  Pink
FFD700  Gold
FFD800  School bus Yellow
FFE5B4  Peach
FFFF00  Yellow
FFFFF0  Ivory
FFFFFF  White    

EXAMPLES

This distribution contains an example script in its examples/ directory.

AUTHOR

Original JavaScript code by Chirag Mehta (http://chir.ag/projects/name-that-color/)

Ported to Perl by Zoffix Znet, <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/, http://mind-power-book.com/)

BUGS

Please report any bugs or feature requests to bug-app-colornamer at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ColorNamer. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc App::ColorNamer

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2010 Zoffix Znet.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.