[PHP-CVS] cvs: php4 /pear/Experimental/Image color_helper.php
uw Wed Mar 28 01:51:11 2001 EDT Added files: /php4/pear/Experimental/Image color_helper.php Log: Widget functions to deal with colors when creating images. I'm not sure where I should place this, lets wait for the next classes (gtext, gbutton) before we take care on the correct directory structure so we can see if it's worth it's own directory. Index: php4/pear/Experimental/Image/color_helper.php +++ php4/pear/Experimental/Image/color_helper.php ?php /** * Widget stuff: color translation, ... * * Several widget functions to deal with images especially simple * functions to convert userdefined colors into RGB colors. * * @author Ulf Wendel [EMAIL PROTECTED] * @version $Id: color_helper.php,v 1.1 2001/03/28 09:51:11 uw Exp $ */ class ColorHelper { /** * Mapping from named colors to RGB values. * * @var array * @see color2RGB() */ var $colornames = array( "white"= array(255, 255, 255), "black"= array(0, 0, 0), "red" = array(255, 0, 0), "green"= array(0, 255, 0), "blue" = array(0, 0, 255) ); /** * Translates a userdefined color specification into an array of RGB integer values. * * Several formats can be handled. HTML like hexadecimal colors like #f0ff00, * names colors, arrays of RGB integer values and strings with percentage values * like %100,%50,%20. If the format is unknown black gets returned [0, 0, 0]. * * @var mixed Color in various formats: #f0f0f0, %20,%100,%0, * named - black, white..., [int 0 - 255, int 0 - 255, int 0 - 255] * @return array RGB color [int red, int green, int blue] * @access public * @see $colornames, HTMLColor2RGB(), PercentageColor2RGB(), NamedColor2RGB() */ function color2RGB($color) { if (is_array($color)) { // looks good... if (3 == count($color)) { // check the range foreach ($color as $k = $v) { if ($v 0) $color[$k] = 0; else if ($v 255) $color[$k] = 255; else $color[$k] = (int)$v; } return $color; } // unknown format - return black return array(0, 0 , 0); } // #f0f0f0 if ("#" == $color{0}) return $this-HTMLColor2RGB($color); // %50,%100,%50 if ("%" == $color{0}) return $this-PercentageColor2RGB($color); // might be a color name return $this-NamedColor2RGB($color); } // end func color2RGB /** * Allocates a color in the given image. * * Userdefined color specifications get translated into * an array of rgb values. * * @paramresourceImage handle * @parammixed (Userdefined) color specification * @return resourceImage color handle * @see color2RGB() * @access public */ function allocateColor($img, $color) { $color = $this-color2RGB($color); return ImageColorAllocate($img, $color[0], $color[1], $color[2]); } // end func allocateColor /** * Returns the RGB integer values of an HTML like hexadecimal color like #00ff00. * * @paramstring HTML like hexadecimal color like #00ff00 * @return array [int red, int green, int blue], * returns black [0, 0, 0] for invalid strings. * @access public */ function HTMLColor2RGB($color) { if (strlen($color) != 7) return array(0, 0, 0); return array( hexdec(substr($color, 1, 2)), hexdec(substr($color, 3, 2)), hexdec(substr($color, 5, 2)) ); } // end func HTMLColor2RGB /** * Returns the RGB interger values of a named color, [0,0,0] if unknown. * * The class variable $colornames is used to resolve * the color names. Modify it if neccessary. * * @paramstring Case insensitive color name. * @return array [int red, int green, int blue], * returns black [0, 0, 0] if the color is unknown. * @access public * @see $colornames */ function NamedColor2RGB($color) { $color = strtolower($color); if (!isset($this-colornames[$color])) return array(0, 0, 0); return
Re: [PHP-CVS] cvs: php4 /pear/Experimental/Image color_helper.php
On Wed, 28 Mar 2001, Ulf Wendel wrote: I'm not sure where I should place this, lets wait for the next classes (gtext, gbutton) before we take care on the correct directory structure so we can see if it's worth it's own directory. There is allready the Image folder in PEAR. Maybe there and rename the class to something like Image_Color. The text and button classes could then be Image_Text and Image_Button? -- Mika Tuupola http://www.appelsiini.net/~tuupola/ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear/Experimental/Image color_helper.php
sbergmann Wed Mar 28 22:55:15 2001 EDT Modified files: /php4/pear/Experimental/Image color_helper.php Log: Added web-safe colors list. Index: php4/pear/Experimental/Image/color_helper.php diff -u php4/pear/Experimental/Image/color_helper.php:1.2 php4/pear/Experimental/Image/color_helper.php:1.3 --- php4/pear/Experimental/Image/color_helper.php:1.2 Wed Mar 28 05:08:11 2001 +++ php4/pear/Experimental/Image/color_helper.php Wed Mar 28 22:55:15 2001 @@ -16,7 +16,7 @@ // | Authors: Ulf Wendel [EMAIL PROTECTED]| // +--+ // -// $Id: color_helper.php,v 1.2 2001/03/28 13:08:11 uw Exp $ +// $Id: color_helper.php,v 1.3 2001/03/29 06:55:15 sbergmann Exp $ // /** @@ -26,7 +26,7 @@ * functions to convert userdefined colors into RGB colors. * * @author Ulf Wendel [EMAIL PROTECTED] -* @version $Id: color_helper.php,v 1.2 2001/03/28 13:08:11 uw Exp $ +* @version $Id: color_helper.php,v 1.3 2001/03/29 06:55:15 sbergmann Exp $ */ class ColorHelper { @@ -38,11 +38,146 @@ * @see color2RGB() */ var $colornames = array( - "white"= array(255, 255, 255), - "black"= array(0, 0, 0), - "red" = array(255, 0, 0), - "green"= array(0, 255, 0), - "blue" = array(0, 0, 255) +"AliceBlue" = array(240,248,255), +"AntiqueWhite" = array(250,235,215), +"Aqua" = array(0,255,255), +"Aquamarine" = array(127255212), +"Azure" = array(240,255,255), +"Beige" = array(245,245,220), +"Bisque" = array(255,228,196), +"Black" = array(0,0,0), +"BlanchedAlmond" = array(255,235,205), +"Blue" = array(0,0,255), +"BlueViolet" = array(138,43,226), +"Brown" = array(165,42,42), +"BurlyWood" = array(222,184,135), +"CadetBlue" = array(95,158,160), +"Chartreuse" = array(127,255,0), +"Chocolate" = array(210,105,30), +"Coral" = array(255,127,80), +"CornflowerBlue" = array(100,149,237), +"Cornsilk" = array(255,248,220), +"Crimson" = array(220,20,60), +"Cyan" = array(0,255,255), +"DarkBlue" = array(0,0,13), +"DarkCyan" = array(0,139,139), +"DarkGoldenrod" = array(184,134,11), +"DarkGray" = array(169,169,169), +"DarkGreen" = array(0,100,0), +"DarkKhaki" = array(189,183,107), +"DarkMagenta" = array(139,0,139), +"DarkOliveGreen" = array(85,107,47), +"DarkOrange" = array(255,140,0), +"DarkOrchid" = array(153,50,204), +"DarkRed" = array(139,0,0), +"DarkSalmon" = array(233,150,122), +"DarkSeaGreen" = array(143,188,143), +"DarkSlateBlue" = array(72,61,139), +"DarkSlateGray" = array(47,79,79), +"DarkTurquoise" = array(0,206,209), +"DarkViolet" = array(148,0,211), +"DeepPink" = array(255,20,147), +"DeepSkyBlue" = array(0,191,255), +"DimGray" = array(105,105,105), +"DodgerBlue" = array(30,144,255), +"FireBrick" = array(178,34,34), +"FloralWhite" = array(255,250,240), +"ForestGreen" = array(34,139,34), +"Fuchsia" = array(255,0,255), +"Gainsboro" = array(220,220,220), +"GhostWhite" = array(248,248,255), +"Gold" = array(255,215,0), +"Goldenrod" = array(218,165,32), +"Gray" = array(128,128,128), +"Green" = array(0,128,0), +"GreenYellow" = array(173,255,47), +