$color = str_replace("#", "", $hex);
// Make sure it's 6 digits
- if ( strlen($color) === 3 ) {
+ if( strlen($color) === 3 ) {
$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
- } else if ( strlen($color) != 6 ) {
+ } else if( strlen($color) != 6 ) {
throw new Exception("HEX color needs to be 6 or 3 digits long");
}
$G = hexdec($color[2].$color[3]);
$B = hexdec($color[4].$color[5]);
- $HSL = array();
+ $HSL = [];
$var_R = ($R / 255);
$var_G = ($G / 255);
* @return string HEX string
* @throws Exception "Bad HSL Array"
*/
- public static function hslToHex( $hsl = array() ){
+ public static function hslToHex( $hsl = [] ){
// Make sure it's HSL
- if (empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) {
+ if(empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) {
throw new Exception("Param was not an HSL array");
}
- list($H,$S,$L) = array( $hsl['H']/360,$hsl['S'],$hsl['L'] );
+ list($H,$S,$L) = [ $hsl['H']/360,$hsl['S'],$hsl['L'] ];
- if ( $S == 0 ) {
+ if( $S == 0 ) {
$r = $L * 255;
$g = $L * 255;
$b = $L * 255;
} else {
- if ($L<0.5) {
+ if($L<0.5) {
$var_2 = $L*(1+$S);
} else {
$var_2 = ($L+$S) - ($S*$L);
* @return string RGB string
* @throws Exception "Bad RGB Array"
*/
- public static function rgbToHex( $rgb = array() ){
+ public static function rgbToHex( $rgb = [] ){
// Make sure it's RGB
- if (empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) {
+ if(empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) {
throw new Exception("Param was not an RGB array");
}
*/
public function makeGradient( $amount = self::DEFAULT_ADJUST ) {
// Decide which color needs to be made
- if ( $this->isLight() ) {
+ if( $this->isLight() ) {
$lightColor = $this->_hex;
$darkColor = $this->darken($amount);
} else {
}
// Return our gradient array
- return array( "light" => $lightColor, "dark" => $darkColor );
+ return [ "light" => $lightColor, "dark" => $darkColor ];
}
// Return the new value in HEX
return self::hslToHex($hsl);
}
-
+
/**
* Returns your color's HSL array
*/
public function getRgb() {
return $this->_rgb;
}
-
+
/**
* Returns the cross browser CSS3 gradient
* @param int $amount Optional: percentage amount to light/darken the gradient
*/
private function _darken( $hsl, $amount = self::DEFAULT_ADJUST){
// Check if we were provided a number
- if ( $amount ) {
+ if( $amount ) {
$hsl['L'] = ($hsl['L'] * 100) - $amount;
$hsl['L'] = ($hsl['L'] < 0) ? 0:$hsl['L']/100;
} else {
// We need to find out how much to darken
- $hsl['L'] = $hsl['L']/2 ;
+ $hsl['L'] = $hsl['L']/2;
}
return $hsl;
*/
private function _lighten( $hsl, $amount = self::DEFAULT_ADJUST){
// Check if we were provided a number
- if ( $amount ) {
+ if( $amount ) {
$hsl['L'] = ($hsl['L'] * 100) + $amount;
$hsl['L'] = ($hsl['L'] > 100) ? 1:$hsl['L']/100;
} else {
$gmix = (($rgb1['G'] * $r1) + ($rgb2['G'] * $r2)) / 2;
$bmix = (($rgb1['B'] * $r1) + ($rgb2['B'] * $r2)) / 2;
- return array('R' => $rmix, 'G' => $gmix, 'B' => $bmix);
+ return ['R' => $rmix, 'G' => $gmix, 'B' => $bmix];
}
/**
* @return int
*/
private static function _huetorgb( $v1,$v2,$vH ) {
- if ( $vH < 0 ) {
+ if( $vH < 0 ) {
$vH += 1;
}
- if ( $vH > 1 ) {
+ if( $vH > 1 ) {
$vH -= 1;
}
- if ( (6*$vH) < 1 ) {
+ if( (6*$vH) < 1 ) {
return ($v1 + ($v2 - $v1) * 6 * $vH);
}
- if ( (2*$vH) < 1 ) {
+ if( (2*$vH) < 1 ) {
return $v2;
}
- if ( (3*$vH) < 2 ) {
+ if( (3*$vH) < 2 ) {
return ($v1 + ($v2-$v1) * ( (2/3)-$vH ) * 6);
}
$color = str_replace("#", "", $hex);
// Make sure it's 6 digits
- if ( strlen($color) == 3 ) {
+ if( strlen($color) == 3 ) {
$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
- } else if ( strlen($color) != 6 ) {
+ } else if( strlen($color) != 6 ) {
throw new Exception("HEX color needs to be 6 or 3 digits long");
}