src/Color.php
public static function fromHEX($hex)
    {
        $hex = preg_replace('/[^0-9A-Fa-f]/', '', $hex);
        $rgb = [];
        if (strlen($hex) == 6) {
            $colorVal = hexdec($hex);
            $rgb['red'] = 0xFF & ($colorVal >> 0x10);
            $rgb['green'] = 0xFF & ($colorVal >> 0x8);
            $rgb['blue'] = 0xFF & $colorVal;
        } elseif (strlen($hex) == 3) {
            $rgb['red'] = hexdec(str_repeat(substr($hex, 0, 1), 2));
            $rgb['green'] = hexdec(str_repeat(substr($hex, 1, 1), 2));
            $rgb['blue'] = hexdec(str_repeat(substr($hex, 2, 1), 2));
        } else {
            throw new InvalidArgumentException('Given color does not adhere to hexadecimal format');
        }

        return self::fromRGB($rgb['red'], $rgb['green'], $rgb['blue']);
    }
public static function fromHEX($hex)
    {
        $hex = preg_replace('/[^0-9A-Fa-f]/', '', $hex);
        $rgb = [];
        if (strlen($hex) == 6) {
            $colorVal = hexdec($hex);
            $rgb['red'] = 0xFF & ($colorVal >> 0x10);
            $rgb['green'] = 0xFF & ($colorVal >> 0x8);
            $rgb['blue'] = 0xFF & $colorVal;
        } elseif (strlen($hex) == 3) {
            $rgb['red'] = hexdec(str_repeat(substr($hex, 0, 1), 2));
            $rgb['green'] = hexdec(str_repeat(substr($hex, 1, 1), 2));
            $rgb['blue'] = hexdec(str_repeat(substr($hex, 2, 1), 2));
        } else {
            throw new InvalidArgumentException('Given color does not adhere to hexadecimal format');
        }

        return self::fromRGB($rgb['red'], $rgb['green'], $rgb['blue']);
    }
public static function fromHEX ( $ hex ) { $ hex = preg_replace ( '/[^0-9A-Fa-f]/' , '' , $ hex ) ; $ rgb = [ ] ; if ( strlen ( $ hex ) == 6 ) { $ colorVal = hexdec ( $ hex ) ; $ rgb [ 'red' ] = 0xFF & ( $ colorVal >> 0x10 ) ; $ rgb [ 'green' ] = 0xFF & ( $ colorVal >> 0x8 ) ; $ rgb [ 'blue' ] = 0xFF & $ colorVal ; } elseif ( strlen ( $ hex ) == 3 ) { $ rgb [ 'red' ] = hexdec ( str_repeat ( substr ( $ hex , 0 , 1 ) , 2 ) ) ; $ rgb [ 'green' ] = hexdec ( str_repeat ( substr ( $ hex , 1 , 1 ) , 2 ) ) ; $ rgb [ 'blue' ] = hexdec ( str_repeat ( substr ( $ hex , 2 , 1 ) , 2 ) ) ; } else { throw new InvalidArgumentException ( 'Given color does not adhere to hexadecimal format' ) ; } return self :: fromRGB ( $ rgb [ 'red' ] , $ rgb [ 'green' ] , $ rgb [ 'blue' ] ) ; }
Creates a Color instance based on the given Hexadecimal-formatted color.

@param string $hex A hexadecimal color value, the # isn't required but can be given

@return Color
Creates a Color instance based on the given Hexadecimal - formatted color .