src/classes/CCImage.php
public function get_luminance( $num_samples = 10 ) 
	{
		$x_step = (int) $this->width / $num_samples;
		$y_step = (int) $this->height / $num_samples;

		$total_lum = 0;
		$sample_no = 1;

		for ( $x=0; $x<$this->width; $x+=$x_step ) 
		{
			for ( $y=0; $y<$this->height; $y+=$y_step ) 
			{
				$rgb = imagecolorat($this->image_context, $x, $y);
				$r = ($rgb >> 16) & 0xFF;
				$g = ($rgb >> 8) & 0xFF;
				$b = $rgb & 0xFF;

				$lum = ($r+$r+$b+$g+$g+$g)/6;

				$total_lum += $lum;
				$sample_no++;
			}
		}

		return (int) ( $total_lum / $sample_no );
	}
public function get_luminance( $num_samples = 10 ) 
	{
		$x_step = (int) $this->width / $num_samples;
		$y_step = (int) $this->height / $num_samples;

		$total_lum = 0;
		$sample_no = 1;

		for ( $x=0; $x<$this->width; $x+=$x_step ) 
		{
			for ( $y=0; $y<$this->height; $y+=$y_step ) 
			{
				$rgb = imagecolorat($this->image_context, $x, $y);
				$r = ($rgb >> 16) & 0xFF;
				$g = ($rgb >> 8) & 0xFF;
				$b = $rgb & 0xFF;

				$lum = ($r+$r+$b+$g+$g+$g)/6;

				$total_lum += $lum;
				$sample_no++;
			}
		}

		return (int) ( $total_lum / $sample_no );
	}
public function get_luminance ( $ num_samples = 10 ) { $ x_step = ( int ) $ this -> width / $ num_samples ; $ y_step = ( int ) $ this -> height / $ num_samples ; $ total_lum = 0 ; $ sample_no = 1 ; for ( $ x = 0 ; $ x < $ this -> width ; $ x += $ x_step ) { for ( $ y = 0 ; $ y < $ this -> height ; $ y += $ y_step ) { $ rgb = imagecolorat ( $ this -> image_context , $ x , $ y ) ; $ r = ( $ rgb >> 16 ) & 0xFF ; $ g = ( $ rgb >> 8 ) & 0xFF ; $ b = $ rgb & 0xFF ; $ lum = ( $ r + $ r + $ b + $ g + $ g + $ g ) / 6 ; $ total_lum += $ lum ; $ sample_no ++ ; } } return ( int ) ( $ total_lum / $ sample_no ) ; }
Get the average luminance of the image

@param int 	$num_samples
@return int	( 1-255 )

@thanks to: http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
Get the average luminance of the image