Brethern --

Is there a way to pass an RGB value to a function/module/etc and get back a fairly simple color name?

All I am looking to do is determine if a color is red, black, green, yellow, blue, etc (not mauve, terracotta, or taupe) based on it's RGB value.

The RGB value is not something nice and round like 255,0,0 for red but 223,8,13 (which still looks really red). So I can't do a look up in rgb.txt because there isn't an entry for that color.

I have tried using GD's
colorClosest $image->colorClosest(red,green,blue) object method This returns the index of the color closest in the color table to the +red green and blue components specified. If no colors have yet been a +llocated, then this call returns -1. Example: $apricot = $myImage->colorClosest(255,200,180);
and then turn that into an RGB colorset so I can do a look up of the color via:
rgb $image->rgb(colorIndex) object method This returns a list containing the red, green and blue components of t +he specified color index. Example: @RGB = $myImage->rgb($peachy);
But for the example I gave for red above, it returns the exact same RGB numbers.

Couldn't find any modules on CPAN that would do what I want or out on the Net.

I figure this is a kind of subjective request ("does this look blue to you?") and that I'll probably have to write a routine that has a range of numbers that "equal" blue or red or whatever but am hoping this has already been done.

Thanks,
Matt

In reply to RGB values and color name by mdog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.