Forum Moderators: coopster

Message Too Old, No Replies

PHP, RGB & CSS

Generating RGB color values on the fly

         

dartar

5:47 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



I'm using PHP for passing to a dynamic CSS stylesheet specific RGB values, that will be used by several elements of the page (something like theme colors).

Ex.

test.php:

<link href="css/styles.php?t=<?php echo $theme;?>" rel="stylesheet type="text/css" />

css/styles.php:

div.footer {background: #<?php echo $t;?>}

In particular, to simulate a watermark effect, I'm passing two distinct RGB values: the first value (say, A) is for the background color, the second slightly lighter value (B) for the font color of large headers that appear in the foreground.

The result is a sort of alpha-transparence for foreground text.

The problem is that, for any background color A, I have to manually check the equivalent RGB value of a 10% lighter foreground color B.

I was wondering if there is a way for passing to the CSS stylesheet just the background color value and have a script do the job of calculating RGB values that are N% lighter or darker than the original color.

Any ideas?

dartar

7:18 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



OK, I've just found RGB -> HSL and HSL -> RGB conversion formulas.

I hope I'll be able to implement them in a script that does what I want.

If someone has already worked on similar problems, hints and suggestions are still welcome :-)

coopster

10:14 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, dartar!

I was just about to search for conversion formulas as I know our graphics developers do variations quite often with their software packages -- then a power outage struck.

I've not yet worked with shading variations in PHP, so I'm looking forward to your findings -- coopster