Hi Jack, Great! I'm definitely looking forward to your Zend_Color proposal. To give you some ideas, here's my my implementation which I wrote 2 years ago for Sourdough Framework:
Sourdough Framework, http://sourdough.phpee.com/ see util/Sd_Color (Sd_Util/Sd_Color.class.php) component API: http://sourdough.phpee.com/api/sourdough/util/Sd_Color.html It supports RGB/Hex/HSB/CMYK conversions. There is even a funny method called guessName() which tries to get the closest matching color name of any supplied color. Would be nice to find something like this in your proposal as well. Take care Philip Jack Sleight wrote: > Here are some code examples of the usage at present. Please note: Dec = > Decimals, Pc = Percentages, Frac = Fractions, Deg = Degrees > > // Get RGB object from hex code > $rgb = Jack_Color::hexToRgb('#0000ff'); > > // Get RGB object named color > $rgb = Jack_Color::namedToRgb('LightBlue'); > > // Create an RGB object > $rgb = new Jack_Color_Rgb(0, 0, 255); > > // Create an RGB object using percentages > $rgb = new Jack_Color_Rgb(0, 0, 100, Jack_Color_Rgb::PC); > > // Get the RGB values > $rgb = new Jack_Color_Rgb(0, 0, 255); > $rgb->getDec(); // array(0, 0, 255) > $rgb->getPc(); // array(0, 0, 100) > $rgb->getFrac(); // array(0, 0, 1) > $rgb->getHex(); // "0000ff" > echo $rgb; // "#0000ff" > $rgb->getCssRgbDec(); // "rgb(0,0,255)" > $rgb->getCssRgbPc(); // "rgb(0%,0%,100%)" > > // Make a colour web safe > $rgb = Jack_Color::hexToRgb('#3d3dd3'); > $rgb->makeWebSafe(); > $rgb->getHex(); // "3333cc" > > // Check W3C visibility > $color1 = Jack_Color::hexToRgb('#ffffff'); > $color2 = Jack_Color::hexToRgb('#000000'); > $color1->passesW3cContrast($color2); // true > > // Convert RGB to HSL > $rgb = new Jack_Color_Rgb(51, 51, 204); > $hsl = $rgb->getHsl(); > > // Get HSL values > $hsl->getDegPc(); // array(240, 75, 80) > $hsl->getCssHsl(); // "hsl(240,75%,80%)" > > // Modify color variables > $hsl = new Jack_Color_Hsl(240, 75, 80); > $hsl->adjLightness(10); > $hsl->adjLightness(-10); > > // Create a 10 step gradient from black to white > // This implements ArrayIterator > $gradient = new Jack_Color_Gradient(array( > new Jack_Color_Rgb(0, 0, 0), > new Jack_Color_Rgb(255, 255, 255) > ), 10);
