src/SyHolloway/MrColor/Extension/Formatter.php
public function loadRgbString(Color $color, $subject)
    {
        $subject = trim($subject);

        $subject = str_replace(array('rgba', 'rgb', '(', ')', ';', ' '), '', $subject);

        $rgbnum = explode(',', $subject);

        if (count($rgbnum) !== 3 && count($rgbnum) !== 4) {
            return false;
        }

        foreach ($rgbnum as &$val) {
            $val = floatval(trim($val));
        }

        $rgb = array(
            'red' => $rgbnum[0],
            'green' => $rgbnum[1],
            'blue' => $rgbnum[2]
        );

        if (isset($rgbnum[3])) {
            $rgb['alpha'] = $rgbnum[3];
        }

        $color->bulkUpdate($rgb);

        return $color;
    }
public function loadRgbString(Color $color, $subject)
    {
        $subject = trim($subject);

        $subject = str_replace(array('rgba', 'rgb', '(', ')', ';', ' '), '', $subject);

        $rgbnum = explode(',', $subject);

        if (count($rgbnum) !== 3 && count($rgbnum) !== 4) {
            return false;
        }

        foreach ($rgbnum as &$val) {
            $val = floatval(trim($val));
        }

        $rgb = array(
            'red' => $rgbnum[0],
            'green' => $rgbnum[1],
            'blue' => $rgbnum[2]
        );

        if (isset($rgbnum[3])) {
            $rgb['alpha'] = $rgbnum[3];
        }

        $color->bulkUpdate($rgb);

        return $color;
    }
public function loadRgbString ( Color $ color , $ subject ) { $ subject = trim ( $ subject ) ; $ subject = str_replace ( array ( 'rgba' , 'rgb' , '(' , ')' , ';' , ' ' ) , '' , $ subject ) ; $ rgbnum = explode ( ',' , $ subject ) ; if ( count ( $ rgbnum ) !== 3 && count ( $ rgbnum ) !== 4 ) { return false ; } foreach ( $ rgbnum as & $ val ) { $ val = floatval ( trim ( $ val ) ) ; } $ rgb = array ( 'red' => $ rgbnum [ 0 ] , 'green' => $ rgbnum [ 1 ] , 'blue' => $ rgbnum [ 2 ] ) ; if ( isset ( $ rgbnum [ 3 ] ) ) { $ rgb [ 'alpha' ] = $ rgbnum [ 3 ] ; } $ color -> bulkUpdate ( $ rgb ) ; return $ color ; }
Loads a color object from an rgb or rgba string

@param object $color Color object
@param mixed
@return object Color object
Loads a color object from an rgb or rgba string