public function setFromHex($hex, $alpha = 0)
    {
        if (!preg_match(self::$HexRegex, $hex)) {
            throw new \InvalidArgumentException(sprintf(
                    'Inavlid Hex Color "%s"', $hex
            ));
        }

        $ehex = ltrim($hex, '#');

        if (strlen($ehex) === 3) {
            $ehex = $ehex[0] . $ehex[0] .
                    $ehex[1] . $ehex[1] .
                    $ehex[2] . $ehex[2];
        }

        $color = array_map('hexdec', str_split($ehex, 2));

        return $this->setRed($color[0])
                        ->setGreen($color[1])
                        ->setBlue($color[2])
                        ->setAlpha($alpha);
    }
public function setFromHex($hex, $alpha = 0)
    {
        if (!preg_match(self::$HexRegex, $hex)) {
            throw new \InvalidArgumentException(sprintf(
                    'Inavlid Hex Color "%s"', $hex
            ));
        }

        $ehex = ltrim($hex, '#');

        if (strlen($ehex) === 3) {
            $ehex = $ehex[0] . $ehex[0] .
                    $ehex[1] . $ehex[1] .
                    $ehex[2] . $ehex[2];
        }

        $color = array_map('hexdec', str_split($ehex, 2));

        return $this->setRed($color[0])
                        ->setGreen($color[1])
                        ->setBlue($color[2])
                        ->setAlpha($alpha);
    }
public function setFromHex ( $ hex , $ alpha = 0 ) { if ( ! preg_match ( self :: $ HexRegex , $ hex ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Inavlid Hex Color "%s"' , $ hex ) ) ; } $ ehex = ltrim ( $ hex , '#' ) ; if ( strlen ( $ ehex ) === 3 ) { $ ehex = $ ehex [ 0 ] . $ ehex [ 0 ] . $ ehex [ 1 ] . $ ehex [ 1 ] . $ ehex [ 2 ] . $ ehex [ 2 ] ; } $ color = array_map ( 'hexdec' , str_split ( $ ehex , 2 ) ) ; return $ this -> setRed ( $ color [ 0 ] ) -> setGreen ( $ color [ 1 ] ) -> setBlue ( $ color [ 2 ] ) -> setAlpha ( $ alpha ) ; }
Set color  from hex string

@param string  $hex   color in hex format
@param integer $alpha alpha value

@return \Jaguar\Color\RGBColor
Set color from hex string