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).
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).
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".
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 ""
This should work pretty much anywhere, actually. As long as the browser supports Javascript, at least.