original_string: protected function getHighestEnergyPoint(\Imagick $image)
      {
          $size = $image->getImageGeometry();
          // It's more performant doing random pixel uplook via GD
          $im = imagecreatefromstring($image->getImageBlob());
          if ($im === false) {
              $msg = 'GD failed to create image from string';
              throw new \Exception($msg);
          }
          $xcenter = 0;
          $ycenter = 0;
          $sum = 0;
          // Only sample 1/50 of all the pixels in the image
          $sampleSize = round($size['height']*$size['width'])/50;
  
          for ($k=0; $k<$sampleSize; $k++) {
              $i = mt_rand(0, $size['width']-1);
              $j = mt_rand(0, $size['height']-1);
  
              $rgb = imagecolorat($im, $i, $j);
              $r = ($rgb >> 16) & 0xFF;
              $g = ($rgb >> 8) & 0xFF;
              $b = $rgb & 0xFF;
  
              $val = $this->rgb2bw($r, $g, $b);
              $sum += $val;
              $xcenter += ($i+1)*$val;
              $ycenter += ($j+1)*$val;
          }
  
          if ($sum) {
              $xcenter /= $sum;
              $ycenter /= $sum;
          }
  
          $point = array('x' => $xcenter, 'y' => $ycenter, 'sum' => $sum/round($size['height']*$size['width']));
  
          return $point;
      }
code: protected function getHighestEnergyPoint(\Imagick $image)
      {
          $size = $image->getImageGeometry();
          // It's more performant doing random pixel uplook via GD
          $im = imagecreatefromstring($image->getImageBlob());
          if ($im === false) {
              $msg = 'GD failed to create image from string';
              throw new \Exception($msg);
          }
          $xcenter = 0;
          $ycenter = 0;
          $sum = 0;
          // Only sample 1/50 of all the pixels in the image
          $sampleSize = round($size['height']*$size['width'])/50;
  
          for ($k=0; $k<$sampleSize; $k++) {
              $i = mt_rand(0, $size['width']-1);
              $j = mt_rand(0, $size['height']-1);
  
              $rgb = imagecolorat($im, $i, $j);
              $r = ($rgb >> 16) & 0xFF;
              $g = ($rgb >> 8) & 0xFF;
              $b = $rgb & 0xFF;
  
              $val = $this->rgb2bw($r, $g, $b);
              $sum += $val;
              $xcenter += ($i+1)*$val;
              $ycenter += ($j+1)*$val;
          }
  
          if ($sum) {
              $xcenter /= $sum;
              $ycenter /= $sum;
          }
  
          $point = array('x' => $xcenter, 'y' => $ycenter, 'sum' => $sum/round($size['height']*$size['width']));
  
          return $point;
      }
code_tokens: protected function getHighestEnergyPoint ( \ Imagick $ image ) { $ size = $ image -> getImageGeometry ( ) ; // It's more performant doing random pixel uplook via GD $ im = imagecreatefromstring ( $ image -> getImageBlob ( ) ) ; if ( $ im === false ) { $ msg = 'GD failed to create image from string' ; throw new \ Exception ( $ msg ) ; } $ xcenter = 0 ; $ ycenter = 0 ; $ sum = 0 ; // Only sample 1/50 of all the pixels in the image $ sampleSize = round ( $ size [ 'height' ] * $ size [ 'width' ] ) / 50 ; for ( $ k = 0 ; $ k < $ sampleSize ; $ k ++ ) { $ i = mt_rand ( 0 , $ size [ 'width' ] - 1 ) ; $ j = mt_rand ( 0 , $ size [ 'height' ] - 1 ) ; $ rgb = imagecolorat ( $ im , $ i , $ j ) ; $ r = ( $ rgb >> 16 ) & 0xFF ; $ g = ( $ rgb >> 8 ) & 0xFF ; $ b = $ rgb & 0xFF ; $ val = $ this -> rgb2bw ( $ r , $ g , $ b ) ; $ sum += $ val ; $ xcenter += ( $ i + 1 ) * $ val ; $ ycenter += ( $ j + 1 ) * $ val ; } if ( $ sum ) { $ xcenter /= $ sum ; $ ycenter /= $ sum ; } $ point = array ( 'x' => $ xcenter , 'y' => $ ycenter , 'sum' => $ sum / round ( $ size [ 'height' ] * $ size [ 'width' ] ) ) ; return $ point ; }
docstring: By doing random sampling from the image, find the most energetic point on the passed in
  image
  
  @param  \Imagick $image
  @return array
docstring_tokens: By doing random sampling from the image find the most energetic point on the passed in image