开发者

PHP Color Manipulation

I am currently looking into color manipulation / selection etc and have come across the following piece of code. I was wondering of someone could tell me what the following piece of code is doing and break it down for me tha开发者_高级运维nks!

$newVal = round(round(($rgb['red'] / 0x33)) * 0x33);

In particluar what is the 0x33

Thanks in adavnce


It seems to be converting $rgb['red'] the nearest multiple of 0x33.

It's probably doing that so the color will end up on the so-called "web safe" color palette, which (if I recall correctly) consists of colors who's rgb values are multiples of 0x33.

0x33 is the base-16 (hex) representation of 51 (decimal).


0x33 is 51, so it scales the 0-255 value of a single byte to 0-5, and then scales it back out. This results in the value being floored to the highest multiple of 51 lower than the value.


0x33 is just hex value for 33.

I'm not really sure what is happening, but my guess would be it calculates a web safe hex of any color. Or something along these lines.


As @Seth indicated, it's rounding colours to the nearest 'web-safe' colour. It's an old idea, dating from back when most colour displays were 8-bit. One of the people to make it popular was Visibone as their 'websafe colour chart' was their first product.

See Web Colours for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜