Forum Moderators: coopster

Message Too Old, No Replies

Getting similar colors

hex, PHP

         

PokeTech

12:57 am on Apr 13, 2010 (gmt 0)

10+ Year Member



Lets say I have this hexadecimal: #ff0000 red. I'm wondering if there is anyway to get a different shade of red using PHP. I need a function to take any hex and find similar shades. I'm not quite sure if this is possible or how this would be done so any help is much appreciated!

jdMorgan

2:07 am on Apr 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



These hex color codes are 3-bytes in length, with the bytes indicating Red, Green, Blue intensity.
You'll sometimes see the colors expressed as decimal octets, with each octet being the decimal equivalent of each hexadecimal byte of two digits. For example, your #ff0000 hex is 255,0,0 decimal.

Basically, any shade of pure red can be gotten by varying the most-significant byte from 0 to 255 decimal or from 00 to FF hex.

The whole thing works just like the three 'guns' in a color TV tube. For example, Yellow is Red plus Green, such as #FFFF00, purple is Red plus Blue #FF00FF.

You can play around with this even in simple tools like MS Paint (Under Colors->Custom Colors) to get the hang of it.

Is that what you were asking?

Jim

Readie

2:50 am on Apr 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Allow me to build on jdMorgan's post.

Hexadecimal is comparable to the decimal system, with one major difference.

Decimal consists of ten numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9
Hexadecimal consists of sixteen: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
(A = 10
B = 11
C = 12
D = 13
E = 14
F = 15)

So, let's take the hexadecimal value #c0d3fc

Split it up into it's component parts:

c0 - d3 - fc

c0 = ((12 * 16) + 0) = 192
d3 = ((13 * 16) + 3) = 211
fc = ((15 * 16) + 12) = 252

So, the following 2 are, for all intents and purposes, identical:
#c0d3fc
R:192, G:211, B:252