CAsciiArt.php
public function luminanceAreaAverage($img, $x1, $y1, $x2, $y2)
    {
        $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1);
        $luminance = 0;
        
        for ($x = $x1; $x <= $x2; $x++) {
            for ($y = $y1; $y <= $y2; $y++) {
                $rgb   = imagecolorat($img, $x, $y);
                $red   = (($rgb >> 16) & 0xFF);
                $green = (($rgb >> 8) & 0xFF);
                $blue  = ($rgb & 0xFF);
                $luminance += $this->getLuminance($red, $green, $blue);
            }
        }
        
        return $luminance / $numPixels;
    }
public function luminanceAreaAverage($img, $x1, $y1, $x2, $y2)
    {
        $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1);
        $luminance = 0;
        
        for ($x = $x1; $x <= $x2; $x++) {
            for ($y = $y1; $y <= $y2; $y++) {
                $rgb   = imagecolorat($img, $x, $y);
                $red   = (($rgb >> 16) & 0xFF);
                $green = (($rgb >> 8) & 0xFF);
                $blue  = ($rgb & 0xFF);
                $luminance += $this->getLuminance($red, $green, $blue);
            }
        }
        
        return $luminance / $numPixels;
    }
public function luminanceAreaAverage ( $ img , $ x1 , $ y1 , $ x2 , $ y2 ) { $ numPixels = ( $ x2 - $ x1 + 1 ) * ( $ y2 - $ y1 + 1 ) ; $ luminance = 0 ; for ( $ x = $ x1 ; $ x <= $ x2 ; $ x ++ ) { for ( $ y = $ y1 ; $ y <= $ y2 ; $ y ++ ) { $ rgb = imagecolorat ( $ img , $ x , $ y ) ; $ red = ( ( $ rgb >> 16 ) & 0xFF ) ; $ green = ( ( $ rgb >> 8 ) & 0xFF ) ; $ blue = ( $ rgb & 0xFF ) ; $ luminance += $ this -> getLuminance ( $ red , $ green , $ blue ) ; } } return $ luminance / $ numPixels ; }
Get the luminance from a region of an image using average color value.

@param string  $img the image.
@param integer $x1  the area to get pixels from.
@param integer $y1  the area to get pixels from.
@param integer $x2  the area to get pixels from.
@param integer $y2  the area to get pixels from.

@return integer $luminance with a value between 0 and 100.
Get the luminance from a region of an image using average color value .