Example #1
0
 /**
  *
  * Get a Color object using /lib class.color
  * Convert to appropriate type
  *
  * @return string
  *
  */
 function get_color($color, $type)
 {
     $c = new Jetpack_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;
 }
Example #2
0
 /**
  * Get the distance between this color and the given color
  *
  * @param Jetpack_Color $color
  *
  * @return int
  */
 public function getDistanceRgbFrom(Jetpack_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;
 }