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

Commit

Permalink
Merge branch 'master' of https://github.com/mcuadros/crop into mcuadr…
Browse files Browse the repository at this point in the history
…os-master

Conflicts:
	src/stojg/crop/Crop.php
	src/stojg/crop/CropBalanced.php
	src/stojg/crop/CropEntropy.php
  • Loading branch information
jdeniau committed Nov 27, 2013
2 parents 5ee56b1 + 47cde53 commit 97dc761
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/stojg/crop/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/stojg/crop/CropBalanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/stojg/crop/CropEntropy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down

0 comments on commit 97dc761

Please # to comment.