Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30 from christiandavilakoobin/master
Browse files Browse the repository at this point in the history
fixed an error when the source image have a very plain color and it c…
  • Loading branch information
jdeniau authored Mar 27, 2020
2 parents 0ceea67 + 96c38a9 commit a20dcad
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/stojg/crop/CropBalanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ function ($result, $array) {
$centerX = 0;
$centerY = 0;

// Calulate the mean weighted center x and y
$totalPoints = count($points);
for ($idx=0; $idx < $totalPoints; $idx++) {
$centerX += $points[$idx]['x'] * ($points[$idx]['sum'] / $totalWeight);
$centerY += $points[$idx]['y'] * ($points[$idx]['sum'] / $totalWeight);
// If we found a center point, made the calculations to found the coords
if ($totalWeight) {
// Calulate the mean weighted center x and y
$totalPoints = count($points);
for ($idx=0; $idx < $totalPoints; $idx++) {
$centerX += $points[$idx]['x'] * ($points[$idx]['sum'] / $totalWeight);
$centerY += $points[$idx]['y'] * ($points[$idx]['sum'] / $totalWeight);
}
}

// From the weighted center point to the topleft corner of the crop would be
Expand Down

0 comments on commit a20dcad

Please sign in to comment.