public static function toRGBA($color)
  {
    // Check it it's already a RGB color
    if (is_array($color)) {
      if (count($color) == 3 && array_keys($color) === range(0, 2)) {
        return array(
          'red' => $color[0],
          'green' => $color[1],
          'blue' => $color[2],
          'alpha' => 1
        );
      }
      if (count($color) == 4 && array_keys($color) === range(0, 3)) {
        return array(
          'red' => $color[0],
          'green' => $color[1],
          'blue' => $color[2],
          'alpha' => $color[3]
        );
      }
      return array(
        'red' => isset($color['red'])
          ? $color['red']
          : (isset($color['r']) ? $color['r'] : 0),
        'green' => isset($color['green'])
          ? $color['green']
          : (isset($color['g']) ? $color['g'] : 0),
        'blue' => isset($color['blue'])
          ? $color['blue']
          : (isset($color['b']) ? $color['b'] : 0),
        'alpha' => isset($color['alpha'])
          ? $color['alpha']
          : 1
      );
    }
    if (is_string($color)) {
      $color = strtolower($color);
      // Check if it's a X11 color
      if (array_key_exists($color, self::$x11) !== false) {
        $color = self::$x11[$color];
        $color['alpha'] = 1;
        return $color;
      }
      // Check if it's an hexadecimal color
      if (preg_match('/^#[\da-f]{3}$/i', $color)) {
        $color = preg_replace('/([\da-f])/i', '$1$1', $color);
      }
      if (preg_match('/^#[\da-f]{6}$/i', $color)) {
        list($red, $green, $blue) = sscanf($color, "#%02x%02x%02x");
        return array(
          'red' => $red,
          'green' => $green,
          'blue' => $blue,
          'alpha' => 1
        );
      }
    }
    return array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 1);
  }
public static function toRGBA($color)
  {
    // Check it it's already a RGB color
    if (is_array($color)) {
      if (count($color) == 3 && array_keys($color) === range(0, 2)) {
        return array(
          'red' => $color[0],
          'green' => $color[1],
          'blue' => $color[2],
          'alpha' => 1
        );
      }
      if (count($color) == 4 && array_keys($color) === range(0, 3)) {
        return array(
          'red' => $color[0],
          'green' => $color[1],
          'blue' => $color[2],
          'alpha' => $color[3]
        );
      }
      return array(
        'red' => isset($color['red'])
          ? $color['red']
          : (isset($color['r']) ? $color['r'] : 0),
        'green' => isset($color['green'])
          ? $color['green']
          : (isset($color['g']) ? $color['g'] : 0),
        'blue' => isset($color['blue'])
          ? $color['blue']
          : (isset($color['b']) ? $color['b'] : 0),
        'alpha' => isset($color['alpha'])
          ? $color['alpha']
          : 1
      );
    }
    if (is_string($color)) {
      $color = strtolower($color);
      // Check if it's a X11 color
      if (array_key_exists($color, self::$x11) !== false) {
        $color = self::$x11[$color];
        $color['alpha'] = 1;
        return $color;
      }
      // Check if it's an hexadecimal color
      if (preg_match('/^#[\da-f]{3}$/i', $color)) {
        $color = preg_replace('/([\da-f])/i', '$1$1', $color);
      }
      if (preg_match('/^#[\da-f]{6}$/i', $color)) {
        list($red, $green, $blue) = sscanf($color, "#%02x%02x%02x");
        return array(
          'red' => $red,
          'green' => $green,
          'blue' => $blue,
          'alpha' => 1
        );
      }
    }
    return array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 1);
  }
public static function toRGBA ( $ color ) { // Check it it's already a RGB color
 if ( is_array ( $ color ) ) { if ( count ( $ color ) == 3 && array_keys ( $ color ) === range ( 0 , 2 ) ) { return array ( 'red' => $ color [ 0 ] , 'green' => $ color [ 1 ] , 'blue' => $ color [ 2 ] , 'alpha' => 1 ) ; } if ( count ( $ color ) == 4 && array_keys ( $ color ) === range ( 0 , 3 ) ) { return array ( 'red' => $ color [ 0 ] , 'green' => $ color [ 1 ] , 'blue' => $ color [ 2 ] , 'alpha' => $ color [ 3 ] ) ; } return array ( 'red' => isset ( $ color [ 'red' ] ) ? $ color [ 'red' ] : ( isset ( $ color [ 'r' ] ) ? $ color [ 'r' ] : 0 ) , 'green' => isset ( $ color [ 'green' ] ) ? $ color [ 'green' ] : ( isset ( $ color [ 'g' ] ) ? $ color [ 'g' ] : 0 ) , 'blue' => isset ( $ color [ 'blue' ] ) ? $ color [ 'blue' ] : ( isset ( $ color [ 'b' ] ) ? $ color [ 'b' ] : 0 ) , 'alpha' => isset ( $ color [ 'alpha' ] ) ? $ color [ 'alpha' ] : 1 ) ; } if ( is_string ( $ color ) ) { $ color = strtolower ( $ color ) ; // Check if it's a X11 color
 if ( array_key_exists ( $ color , self :: $ x11 ) !== false ) { $ color = self :: $ x11 [ $ color ] ; $ color [ 'alpha' ] = 1 ; return $ color ; } // Check if it's an hexadecimal color
 if ( preg_match ( '/^#[\da-f]{3}$/i' , $ color ) ) { $ color = preg_replace ( '/([\da-f])/i' , '$1$1' , $ color ) ; } if ( preg_match ( '/^#[\da-f]{6}$/i' , $ color ) ) { list ( $ red , $ green , $ blue ) = sscanf ( $ color , "#%02x%02x%02x" ) ; return array ( 'red' => $ red , 'green' => $ green , 'blue' => $ blue , 'alpha' => 1 ) ; } } return array ( 'red' => 0 , 'green' => 0 , 'blue' => 0 , 'alpha' => 1 ) ; }
Change a color format to RGBA

@param  mixed $color Color
@return array        An [red, green, blue, alpha] associative array
Change a color format to RGBA