Beispiel #1
0
 /**
  * Get the distance between this color and the given color
  *
  * @param Color $color
  *
  * @return int
  */
 public function getDistanceRgbFrom(Color $color)
 {
     $rgb1 = $this->toRgbInt();
     $rgb2 = $color->toRgbInt();
     $rDiff = abs($rgb1['red'] - $rgb2['red']);
     $gDiff = abs($rgb1['green'] - $rgb2['green']);
     $bDiff = abs($rgb1['blue'] - $rgb2['blue']);
     // Sum of RGB differences
     $diff = $rDiff + $gDiff + $bDiff;
     return $diff;
 }
Beispiel #2
0
 /**
  *
  * Get a Color object using /lib class.color
  * Convert to appropiatte type
  *
  * @return string
  *
  */
 function get_color($color, $type)
 {
     $c = new Color($color, 'rgb');
     $this->color = $c;
     switch ($type) {
         case 'rgb':
             $color = implode($c->toRgbInt(), ',');
             break;
         case 'hex':
             $color = $c->toHex();
             break;
         case 'hsv':
             $color = implode($c->toHsvInt(), ',');
             break;
         default:
             return $color = $c->toHex();
     }
     return $color;
 }