Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Convert RGB to an actual color

by Anonymous Monk
on Nov 21, 2002 at 23:41 UTC ( #214957=note: print w/replies, xml ) Need Help??

in reply to Convert RGB to an actual color

(1) If you want meaningful names ... There's a file rgb.txt floating around the net with standard names in RGB space. It was originally distributed by the X Windows consortium, found in /usr/lib/X11/rgb.txt if you have one. If you initialize your GD palette with those, and remember the color#->name map after each, you can then use colorClosest() to find the closest name. Warning: You'll need to use the TrueColor option otherwise the 897 colors will overflow your 256 color palette.

You're in luck, CPAN is having a special on rgb.txt: "Color::Rgb - Simple rgb.txt parsing class". The CPAN TGZ includes and rgb.txt.

(2) Or if you want geometric generalizations and want to code it yourself, Color::Object handles HSV/HSL/RGB conversions, and can give you something not unlike angles in colorspace that you could round, interpret, and convert back.

For background on colorspace stuff and all sorts of graphics processing, check out the Graphic Gems series and source archive and the successor journal jgt. They speak C over there, but it's easily transliterated.

-- bill n1vux

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://214957]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2020-08-11 16:38 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (62 votes). Check out past polls.