Unit test for #149.
[akelos.git] / lib / AkColor.php
bloba3a7e730e0efb6a0fe8e1195f537d4363844054f
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4 // +----------------------------------------------------------------------+
5 // | Akelos Framework - http://www.akelos.org |
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
8 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
9 // +----------------------------------------------------------------------+
11 /**
12 * @package ActiveSupport
13 * @subpackage Utils
14 * @author Bermi Ferrer <bermi a.t akelos c.om>
15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
19 require_once(AK_VENDOR_DIR.DS.'pear'.DS.'Image'.DS.'Color.php');
21 class AkColor extends Image_Color
23 function rgbToHex()
25 $rgb = func_get_args();
26 $hex = '';
27 foreach (count($rgb) == 1 ? $rgb[0] : $rgb as $color){
28 $color = dechex($color);
29 $hex .= strlen($color) == 2 ? $color : $color.$color;
31 return $hex;
34 function hexToRgb($hex_color)
36 $hex_color = strtolower(trim($hex_color,'#;&Hh'));
37 return array_map('hexdec',explode('.',wordwrap($hex_color, ceil(strlen($hex_color)/3),'.',1)));
40 function getOpositeHex($hex_color)
42 $rgb = AkColor::hexToRgb($hex_color);
43 foreach ($rgb as $k=>$color){
44 $rgb[$k] = (255-$color < 0 ? 0 : 255-$color);
46 return AkColor::rgbToHex($rgb);
49 function getRandomHex()
51 return AkColor::rgbToHex(rand(0,255),rand(0,255),rand(0,255));