$hexValue ) { if ( isset( $keys[$nr] ) ) { $key = $keys[$nr]; $color->$key = hexdec( $hexValue ) % 256; } } // Set missing values to zero for ( ++$nr; $nr < count( $keys ); ++$nr ) { $key = $keys[$nr]; $color->$key = 0; } return $color; } /** * Creates an ezcGraphColor object from an array of integers * * @param array $array Array of integer color values * @return ezcGraphColor */ static public function fromIntegerArray( array $array ) { // Iterate over array elements $color = new ezcGraphColor(); $keys = array( 'red', 'green', 'blue', 'alpha' ); $nr = 0; foreach ( $array as $colorValue ) { if ( isset( $keys[$nr] ) ) { $key = $keys[$nr++]; $color->$key = ( (int) $colorValue ) % 256; } } // Set missing values to zero for ( ++$nr; $nr < count( $keys ); ++$nr ) { $key = $keys[$nr]; $color->$key = 0; } return $color; } /** * Creates an ezcGraphColor object from an array of floats * * @param array $array Array of float color values * @return ezcGraphColor */ static public function fromFloatArray( array $array ) { // Iterate over array elements $color = new ezcGraphColor(); $keys = array( 'red', 'green', 'blue', 'alpha' ); $nr = 0; foreach ( $array as $colorValue ) { if ( isset( $keys[$nr] ) ) { $key = $keys[$nr++]; $color->$key = ( (float) $colorValue * 255 ) % 256; } } // Set missing values to zero for ( ++$nr; $nr < count( $keys ); ++$nr ) { $key = $keys[$nr]; $color->$key = 0; } return $color; } /** * Tries to detect type of color color definition and returns an * ezcGraphColor object * * @param mixed $color Some kind of color definition * @return ezcGraphColor */ static public function create( $color ) { if ( $color instanceof ezcGraphColor ) { return $color; } elseif ( is_string( $color ) ) { return ezcGraphColor::fromHex( $color ); } elseif ( is_array( $color ) ) { $testElement = reset( $color ); if ( is_int( $testElement ) ) { return ezcGraphColor::fromIntegerArray( $color ); } else { return ezcGraphColor::fromFloatArray( $color ); } } else { throw new ezcGraphUnknownColorDefinitionException( $color ); } } /** * Darkens the color * * @param float $value Percent to darken the color * @return void */ public function darken( $value ) { $color = clone $this; $value = 1 - $value; $color->red = (int) round( $this->red * $value ); $color->green = (int) round( $this->green * $value ); $color->blue = (int) round( $this->blue * $value ); return $color; } } ?>