User:Harthur/ColorConversion: Difference between revisions

(Created page with '= About = download: [http://colorplay.googlecode.com/files/colorCommon.js colorCommon.js] This is a javascript library for converting colors between different color formats. It …')
 
Line 15: Line 15:


example:
example:
<pre>bugzillaRPC.getBug(48875,
<pre>colorCommon.toHex("hsl(142, 45%, 10%)")</pre>
                        function(bug) {alert(bug.summary);},
                        function(errMsg) {alert(errMsg)});</pre>


=== getBugs ===
=== toRgb ===
Retrieves an array of bug objects
gets an Rgb string for a color


parameters:
parameter:
* ids - an array of bug ids
* any valid color string
* callback
* errback


success parameter:
return:
* bugs - An array of objects defined by Bugzilla XML-RPC's [http://www.bugzilla.org/docs/3.0/html/api/Bugzilla/WebService/Bug.html#Bug_Creation_and_Modification getBugs return value]. with properties <tt>id</tt>, <tt>summary</tt>, <tt>creation_time</tt>, <tt>last_change_time</tt>, and the <tt>internals</tt> object which has various other properties.
* a string of the color in rgb format


example:
example:
<pre>bugzillaRPC.getBugs([8117, 2344],
<pre>colorCommon.toRgb("hsv(230, 100%, 10%)")</pre>
                        function(bugs) {alert(bugs[0].summary);},
 
                        function(errMsg) {alert(errMsg)});</pre>
=== toPercent ===
gets an Rgb string in percentile format for a color
 
parameter:
* any valid color string
 
return:
* a string of the color in rgb percentile format
 
example:
<pre>colorCommon.toRgb("#66CCE4")</pre>
 
=== toHsl ===
gets an hsl string for a color
 
parameter:
* any valid color string
 
return:
* a string of the color in hsl format
 
example:
<pre>colorCommon.toHsl("#66CCE4")</pre>
 
=== toHsv ===
gets an hsv string for a color
 
parameter:
* any valid color string
 
return:
* a string of the color in hsv format
 
example:
<pre>colorCommon.toHsv("#66CCE4")</pre>
 
=== rgbValues ===
gets the individual red, green, and blue values for a color string
 
parameter:
* any valid color string
 
return:
* an object with properties <tt>red</tt>, <tt>green</tt>, and <tt>blue</tt>
 
example:
<pre>colorCommon.rgbValues("#66CCE4")["red"]</pre>
 
=== hslValues ===
gets the individual hue, saturation, and lightness values for a color string
 
parameter:
* any valid color string
 
return:
* an object with properties <tt>hue</tt>, <tt>sat</tt>, and <tt>light</tt>
 
example:
<pre>colorCommon.hslValues("#66CCE4")["light"]</pre>
 
=== hsvValues ===
gets the individual hue, saturation, and value values for a color string
 
parameter:
* any valid color string
 
return:
* an object with properties <tt>hue</tt>, <tt>satv</tt>, and <tt>val</tt>
 
example:
<pre>colorCommon.hsvValues("#66CCE4")["satv"]</pre>
 
=== isValid ===
reports whether a color string is a valid color
 
parameter:
* any color string
 
return:
* <tt>true</tt> if it is a valid color, <tt>false</tt> otherwise
 
example:
<pre>colorCommon.isValid("rgb(4000,,)")</pre>
 
=== isValid ===
reports whether a color string is a valid color
 
parameter:
* any color string
 
return:
* <tt>true</tt> if it is a valid color, <tt>false</tt> otherwise
 
example:
<pre>colorCommon.isValid("rgb(4000,,)")</pre>
 
=== luminosity ===
gets the WCAG luminosity for a color.
 
parameter:
* any valid color string
 
return:
* a decimal number from 0 to 1 (0 is black, 1 is white)
example:
<pre>colorCommon.luminosity("#445590")</pre>
 
 
=== contrast ===
gets the WCAG luminosity contrast ratio for a color.
 
parameter:
* any valid color string
 
return:
* a decimal number from 0 to 21 (4.5 is considered minimum for text/background ratio, 7 is good, and 10+ is excellent)
example:
<pre>colorCommon.contrast("hsl(46, 100%, 34%)", "#445590")</pre>
865

edits