color2color Javascript Function

Version 0.2, Released 2012/04/02

GPL v3, Copyright 2012 IndyArmy Network, Inc.

Description

color2color converts a color string in any CSS format (RGB, RGBA, Hex, HSL, HSLA, or HSV) into another format (also RGB, RGBA, Hex, HSL, HSLA, or HSV).

Usage

color2color( string originalColor, [string newColorType( rgba|hex|rgb|hsl|hsla|hsv )], [bool calculateOpacity( false|true )]

The first argument is the original color string in RGB, RGBA, Hex, HSL, HSLA, or HSV format.

The second argument (optional) is which format you'd like the new color string to be in. This will always default to "rgba".

The final argument (optional) will include a calculated opacity against white if the second argument is "rgba".

Examples

var newColor = color2color( "#dfe" ); // Returns ""

var newColor = color2color( "#036", "rgb" ); // Returns ""

var newColor = color2color( "rgba(64,64,64,0.5)" ); // Returns ""

var newColor = color2color( "rgb(64,64,64)", "hex" ); // Returns ""

var newColor = color2color( "#dfe", "rgba", true ); // Returns ""

var newColor = color2color( "hsla(109,100%,37%,1)" ); // Returns ""

var newColor = color2color( "rgba(35,189,0,0.75)", "hsl" ); // Returns ""

Release Notes

GitHub Repository

This should work pretty much anywhere, actually. As long as the browser supports Javascript, at least.