diff --git a/src/stojg/crop/Crop.php b/src/stojg/crop/Crop.php index 380322f..9379447 100644 --- a/src/stojg/crop/Crop.php +++ b/src/stojg/crop/Crop.php @@ -145,7 +145,8 @@ protected function getEntropy($histogram, $area) { $value = 0.0; - for ($idx = 0; $idx < count($histogram); $idx++) { + $colors = count($histogram); + for ($idx = 0; $idx < $colors; $idx++) { // calculates the percentage of pixels having this color value $p = $histogram[$idx]->getColorCount() / $area; // A common way of representing entropy in scalar diff --git a/src/stojg/crop/CropBalanced.php b/src/stojg/crop/CropBalanced.php index d3f2be8..d0b956d 100644 --- a/src/stojg/crop/CropBalanced.php +++ b/src/stojg/crop/CropBalanced.php @@ -102,7 +102,8 @@ function ($result, $array) { $centerY = 0; // Calulate the mean weighted center x and y - for ($idx=0; $idx < count($points); $idx++) { + $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); } @@ -136,8 +137,9 @@ protected function getHighestEnergyPoint(\Imagick $image) { $size = $image->getImageGeometry(); // It's more performant doing random pixel uplook via GD - $image->writeimage('/tmp/image'); - $im = imagecreatefromjpeg('/tmp/image'); + $tmpFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'image' . rand(); + $image->writeimage($tmpFile); + $im = imagecreatefromjpeg($tmpFile); $xcenter = 0; $ycenter = 0; $sum = 0; diff --git a/src/stojg/crop/CropEntropy.php b/src/stojg/crop/CropEntropy.php index 5e6d94d..4d24e70 100644 --- a/src/stojg/crop/CropEntropy.php +++ b/src/stojg/crop/CropEntropy.php @@ -253,7 +253,8 @@ protected function colorEntropy(\Imagick $image) $newHistogram = array(); // Translates a color histogram into a bw histogram - for ($idx = 0; $idx < count($histogram); $idx++) { + $colors = count($histogram); + for ($idx = 0; $idx < $colors; $idx++) { $colors = $histogram[$idx]->getColor(); $grey = $this->rgb2bw($colors['r'], $colors['g'], $colors['b']); if (!isset($newHistogram[$grey])) {