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