src/Utilities/Miscellaneous.php
public static function getInvertedColor($color)
    {
        // Prepare the color for later usage
        $color = trim($color);
        $withHash = Regex::startsWith($color, '#');

        /*
         * Verify and get valid value of color.
         * An exception will be thrown if the value is not a color.
         */
        $validColor = Regex::getValidColorHexValue($color);

        // Grab color's components
        $red = hexdec(substr($validColor, 0, 2));
        $green = hexdec(substr($validColor, 2, 2));
        $blue = hexdec(substr($validColor, 4, 2));

        // Calculate inverted color's components
        $redInverted = self::getValidColorComponent(255 - $red);
        $greenInverted = self::getValidColorComponent(255 - $green);
        $blueInverted = self::getValidColorComponent(255 - $blue);

        // Voila, here is the inverted color
        $invertedColor = sprintf('%s%s%s', $redInverted, $greenInverted, $blueInverted);

        if ($withHash) {
            return sprintf('#%s', $invertedColor);
        }

        return $invertedColor;
    }
public static function getInvertedColor($color)
    {
        // Prepare the color for later usage
        $color = trim($color);
        $withHash = Regex::startsWith($color, '#');

        /*
         * Verify and get valid value of color.
         * An exception will be thrown if the value is not a color.
         */
        $validColor = Regex::getValidColorHexValue($color);

        // Grab color's components
        $red = hexdec(substr($validColor, 0, 2));
        $green = hexdec(substr($validColor, 2, 2));
        $blue = hexdec(substr($validColor, 4, 2));

        // Calculate inverted color's components
        $redInverted = self::getValidColorComponent(255 - $red);
        $greenInverted = self::getValidColorComponent(255 - $green);
        $blueInverted = self::getValidColorComponent(255 - $blue);

        // Voila, here is the inverted color
        $invertedColor = sprintf('%s%s%s', $redInverted, $greenInverted, $blueInverted);

        if ($withHash) {
            return sprintf('#%s', $invertedColor);
        }

        return $invertedColor;
    }
public static function getInvertedColor ( $ color ) { // Prepare the color for later usage $ color = trim ( $ color ) ; $ withHash = Regex :: startsWith ( $ color , '#' ) ; /*
         * Verify and get valid value of color.
         * An exception will be thrown if the value is not a color.
         */ $ validColor = Regex :: getValidColorHexValue ( $ color ) ; // Grab color's components $ red = hexdec ( substr ( $ validColor , 0 , 2 ) ) ; $ green = hexdec ( substr ( $ validColor , 2 , 2 ) ) ; $ blue = hexdec ( substr ( $ validColor , 4 , 2 ) ) ; // Calculate inverted color's components $ redInverted = self :: getValidColorComponent ( 255 - $ red ) ; $ greenInverted = self :: getValidColorComponent ( 255 - $ green ) ; $ blueInverted = self :: getValidColorComponent ( 255 - $ blue ) ; // Voila, here is the inverted color $ invertedColor = sprintf ( '%s%s%s' , $ redInverted , $ greenInverted , $ blueInverted ) ; if ( $ withHash ) { return sprintf ( '#%s' , $ invertedColor ) ; } return $ invertedColor ; }
Returns inverted value of color for given color

@param string $color Hexadecimal value of color to invert (with or without hash), e.g. "dd244c" or "#22a5fe"
@return string
Returns inverted value of color for given color