Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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 Rgb.pm 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2019-07-20 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?