[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/ -> AkColor.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   3  
   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  // +----------------------------------------------------------------------+
  10  
  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>
  17   */
  18  
  19  require_once(AK_VENDOR_DIR.DS.'pear'.DS.'Image'.DS.'Color.php');
  20  
  21  class AkColor extends Image_Color
  22  {
  23      function rgbToHex()
  24      {
  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;
  30          }
  31          return $hex;
  32      }
  33  
  34      function hexToRgb($hex_color)
  35      {
  36          $hex_color = strtolower(trim($hex_color,'#;&Hh'));
  37          return array_map('hexdec',explode('.',wordwrap($hex_color, ceil(strlen($hex_color)/3),'.',1)));
  38      }
  39  
  40      function getOpositeHex($hex_color)
  41      {
  42          $rgb = AkColor::hexToRgb($hex_color);
  43          foreach ($rgb as $k=>$color){
  44              $rgb[$k] = (255-$color < 0 ? 0 : 255-$color);
  45          }
  46          return AkColor::rgbToHex($rgb);
  47      }
  48  
  49      function getRandomHex()
  50      {
  51          return AkColor::rgbToHex(rand(0,255),rand(0,255),rand(0,255));
  52      }
  53  }
  54  
  55  ?>


Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6