Tweak comments
This commit is contained in:
parent
9a552b53c4
commit
e05ec20e06
@ -20,24 +20,24 @@ class AverageHash implements Algorithm
|
|||||||
$resized, $resource, 0, 0, 0, 0,
|
$resized, $resource, 0, 0, 0, 0,
|
||||||
static::SIZE, static::SIZE, imagesx($resource), imagesy($resource));
|
static::SIZE, static::SIZE, imagesx($resource), imagesy($resource));
|
||||||
|
|
||||||
// Create an array of gray-scale pixel value
|
// Create an array of gray-scaled pixel values.
|
||||||
$pixels = array();
|
$pixels = array();
|
||||||
for ($y = 0; $y < static::SIZE; $y++) {
|
for ($y = 0; $y < static::SIZE; $y++) {
|
||||||
for ($x = 0; $x < static::SIZE; $x++) {
|
for ($x = 0; $x < static::SIZE; $x++) {
|
||||||
$rgb = imagecolorsforindex($resized, imagecolorat($resized, $x, $y));
|
$rgb = imagecolorsforindex($resized, imagecolorat($resized, $x, $y));
|
||||||
$pixels[] = floor(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
|
$pixels[] = ($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imagedestroy($resized);
|
imagedestroy($resized);
|
||||||
|
|
||||||
// Calculate the average pixel value
|
// Calculate a mean of gray-scaled pixel value.
|
||||||
$average = floor(array_sum($pixels) / count($pixels));
|
$mean = array_sum($pixels) / count($pixels);
|
||||||
|
|
||||||
$bin = '';
|
$bin = '';
|
||||||
$one = 1;
|
$one = 1;
|
||||||
foreach ($pixels as $pixel) {
|
foreach ($pixels as $pixel) {
|
||||||
$bin .= $pixel > $average ? 1 : 0;
|
$bin .= $pixel > $mean ? 1 : 0;
|
||||||
$one = $one << 1;
|
$one = $one << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user