public static function changeBrightness($hex, $adjustPercentage)
    {
        $rgba = (strlen($hex) == 8);

        $red = self::getRed($hex, false);
        $green = self::getGreen($hex, false);
        $blue = self::getBlue($hex, false);
        if ($adjustPercentage > 0) {
            $red += (255 - $red) * $adjustPercentage;
            $green += (255 - $green) * $adjustPercentage;
            $blue += (255 - $blue) * $adjustPercentage;
        } else {
            $red += $red * $adjustPercentage;
            $green += $green * $adjustPercentage;
            $blue += $blue * $adjustPercentage;
        }

        if ($red < 0) {
            $red = 0;
        } elseif ($red > 255) {
            $red = 255;
        }
        if ($green < 0) {
            $green = 0;
        } elseif ($green > 255) {
            $green = 255;
        }
        if ($blue < 0) {
            $blue = 0;
        } elseif ($blue > 255) {
            $blue = 255;
        }

        $rgb = strtoupper(
            str_pad(dechex($red), 2, '0', 0) .
            str_pad(dechex($green), 2, '0', 0) .
            str_pad(dechex($blue), 2, '0', 0)
        );
        return (($rgba) ? 'FF' : '') . $rgb;
    }
public static function changeBrightness($hex, $adjustPercentage)
    {
        $rgba = (strlen($hex) == 8);

        $red = self::getRed($hex, false);
        $green = self::getGreen($hex, false);
        $blue = self::getBlue($hex, false);
        if ($adjustPercentage > 0) {
            $red += (255 - $red) * $adjustPercentage;
            $green += (255 - $green) * $adjustPercentage;
            $blue += (255 - $blue) * $adjustPercentage;
        } else {
            $red += $red * $adjustPercentage;
            $green += $green * $adjustPercentage;
            $blue += $blue * $adjustPercentage;
        }

        if ($red < 0) {
            $red = 0;
        } elseif ($red > 255) {
            $red = 255;
        }
        if ($green < 0) {
            $green = 0;
        } elseif ($green > 255) {
            $green = 255;
        }
        if ($blue < 0) {
            $blue = 0;
        } elseif ($blue > 255) {
            $blue = 255;
        }

        $rgb = strtoupper(
            str_pad(dechex($red), 2, '0', 0) .
            str_pad(dechex($green), 2, '0', 0) .
            str_pad(dechex($blue), 2, '0', 0)
        );
        return (($rgba) ? 'FF' : '') . $rgb;
    }
public static function changeBrightness ( $ hex , $ adjustPercentage ) { $ rgba = ( strlen ( $ hex ) == 8 ) ; $ red = self :: getRed ( $ hex , false ) ; $ green = self :: getGreen ( $ hex , false ) ; $ blue = self :: getBlue ( $ hex , false ) ; if ( $ adjustPercentage > 0 ) { $ red += ( 255 - $ red ) * $ adjustPercentage ; $ green += ( 255 - $ green ) * $ adjustPercentage ; $ blue += ( 255 - $ blue ) * $ adjustPercentage ; } else { $ red += $ red * $ adjustPercentage ; $ green += $ green * $ adjustPercentage ; $ blue += $ blue * $ adjustPercentage ; } if ( $ red < 0 ) { $ red = 0 ; } elseif ( $ red > 255 ) { $ red = 255 ; } if ( $ green < 0 ) { $ green = 0 ; } elseif ( $ green > 255 ) { $ green = 255 ; } if ( $ blue < 0 ) { $ blue = 0 ; } elseif ( $ blue > 255 ) { $ blue = 255 ; } $ rgb = strtoupper ( str_pad ( dechex ( $ red ) , 2 , '0' , 0 ) . str_pad ( dechex ( $ green ) , 2 , '0' , 0 ) . str_pad ( dechex ( $ blue ) , 2 , '0' , 0 ) ) ; return ( ( $ rgba ) ? 'FF' : '' ) . $ rgb ; }
Adjust the brightness of a color

@param    string        $hex    The colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)
@param    float        $adjustPercentage    The percentage by which to adjust the colour as a float from -1 to 1
@return    string        The adjusted colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)
Adjust the brightness of a color