You are here

function image_focus_get_focal_point_edge_maximizing in Image Focus Crop 6

Same name and namespace in other branches
  1. 7 image_focus.module \image_focus_get_focal_point_edge_maximizing()

Get the focal point using edge-maximizing crop.

@todo However it does not work as expected.

See also

http://jueseph.com/2010/06/opticrop-content-aware-cropping-with-php-and-...

File

./image_focus.module, line 121
Image Focus Crop module.

Code

function image_focus_get_focal_point_edge_maximizing($resource) {
  $w = imagesx($resource);
  $h = imagesy($resource);
  $xcenter = 0;
  $ycenter = 0;
  $sum = 0;
  $n = 100000;
  for ($k = 0; $k < $n; $k++) {
    $i = mt_rand(0, $w - 1);
    $j = mt_rand(0, $h - 1);
    $val = imagecolorat($resource, $i, $j) & 0xff;
    $sum += $val;
    $xcenter += ($i + 1) * $val;
    $ycenter += ($j + 1) * $val;
  }
  $xcenter /= $sum;
  $ycenter /= $sum;
  return array(
    $xcenter,
    $ycenter,
  );
}