Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Converting hex colors to color safe hex

by dhosek (Beadle)
on Apr 11, 2008 at 17:38 UTC ( [id://679786]=note: print w/replies, xml ) Need Help??


in reply to Re: Converting hex colors to color safe hex
in thread Converting hex colors to color safe hex

I think you're overthinking the problem. What you're outlining makes sense if you're trying to get a minimal set of colors (adaptive pallet in Adobe-speak), but for going to websafe sets, rounding each color component individually will get the correct result. So you can do something along the lines of int($val/51+0.5)*51 to get yourself to the set of hex values 00, 33, 66, 99, CC, FF.

But are websafe colors even an issue any more? Who's using 256-color displays these days? This is one of those holdovers from the early days of the web which don't make sense. On the other hand, if you're going to a GIF, then you may want to think about using a proper clustering algorithm to get to the optimal color set. I'd suggest looking at Algorithm::Cluster for that task.

Donald Hosek, Tech Lead at oversee.net
L.A. perl people, we're hiring.
  • Comment on Re^2: Converting hex colors to color safe hex

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2026-01-19 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (122 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.