Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Color Manipulation

Tags:

php

colors

gdlib

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 thanks!

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

In particluar what is the 0x33

Thanks in adavnce

like image 590
Lizard Avatar asked Oct 15 '22 07:10

Lizard


2 Answers

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).

like image 154
Seth Avatar answered Nov 02 '22 23:11

Seth


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.

like image 39
Ignacio Vazquez-Abrams Avatar answered Nov 02 '22 22:11

Ignacio Vazquez-Abrams