PHP color manipulation

I am currently studying color manipulation / selection, etc. and am on the next code snippet. I was wondering if someone could tell me what the following code snippet does, and thanks for breaking it for me!

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

In particular, what is 0x33

Thanks at adavnce

+4
source share
4 answers

It seems that the conversion is $rgb['red'] nearest multiple of 0x33.

This probably makes the color fall into the so-called “Internet-safe” color palette, which (if I remember correctly) consists of colors whose rgb values ​​are multiples of 0x33.

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

+3
source

0x33 is 51, so it scales the value 0-255 of one byte to 0-5, and then scales it back. This causes the value to be overridden to the highest multiple of 51 below the value.

+1
source

0x33 is just the hexadecimal value for 33.

I'm not quite sure what is happening, but I assume that it calculates a web safe hex of any color. Or something like that.

0
source

As pointed out by @Seth, it rounds the colors to the nearest “safe web color”. This is an old idea dating back to when most color displays were 8-bit. One of the people who made it popular was Visibone, as their "websafe color chart" was their first product.

See Web Colors for more details.

0
source

Source: https://habr.com/ru/post/1306750/


All Articles