CSS Code, PHP Code

Convert RGB colors to Hex

Most web developers are quite comfortable using CSS to stylize their websites. But oftentimes they will design (or have designed) a template in Photoshop before creating the HTML template. Sometimes it can be a real headache to convert the RGB colors to the proper hexadecimal values for use in CSS.

So, if this is what you need to do, you can use this color conversion PHP class to do the work for you! It can accept an array with the values of a color as separate RGB component values, and then do the conversion to provide the proper hexadecimal representation. If you need to, you can also use it the other way – to convert hexadecimal color values to RGB representation.

As a side benefit, this PHP class also validates color values in RGB or hexadecimal formats, to determine whether whether or not the values correspond to a valid color.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image