Skip to content

Commit

Permalink
📝 Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed May 11, 2018
1 parent 710672b commit d1188fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Requirements
Installation
------------

*This package has not reached a stable version yet, backwards compatibility may be broken between 0.x releases. Make sure to lock your version if you intend to use this in production!*

Install using composer:

composer require jenssegers/imagehash
Expand All @@ -38,8 +40,8 @@ The library comes with 4 built-in hashing implementations:

- `Jenssegers\ImageHash\Implementation\AverageHash` - Hash based the average image color
- `Jenssegers\ImageHash\Implementation\DifferenceHash` - Hash based on the previous pixel
- `Jenssegers\ImageHash\Implementation\BlockHash` - Hash based on blockhash.io
- `Jenssegers\ImageHash\Implementation\PerceptualHash` - **Still under development**
- `Jenssegers\ImageHash\Implementation\BlockHash` - Hash based on blockhash.io **Still under development**
- `Jenssegers\ImageHash\Implementation\PerceptualHash` - The original pHash **Still under development**

Choose one of these implementations. If you don't know which one to use, try the `DifferenceHash` implementation. Some implementations allow some configuration, be sure to check the constructor.

Expand Down
14 changes: 7 additions & 7 deletions src/Implementations/BlockHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ private function uneven(Image $image)
$blockWidth = $imageWidth / $this->size;
$blockHeight = $imageHeight / $this->size;

// Initialize empty blocks
// Initialize empty blocks.
$blocks = [];
for ($i = 0; $i < $this->size; $i++) {
$blocks[$i] = array_fill(0, $this->size, 0);
}

for ($y = 0; $y < $imageHeight; $y++) {
if ($evenY) {
// Don't bother dividing y, if the size evenly divides by bits
// Don't bother dividing y, if the size evenly divides by bits.
$blockTop = $blockBottom = (int) floor($y / $blockHeight);
$weightTop = 1;
$weightBottom = 0;
Expand All @@ -125,7 +125,7 @@ private function uneven(Image $image)
$weightTop = 1 - $yFrac;
$weightBottom = $yFrac;

// y_int will be 0 on bottom/right borders and on block boundaries
// yInt will be 0 on bottom/right borders and on block boundaries.
if ($yInt > 0 || ($y + 1) === $imageHeight) {
$blockTop = $blockBottom = (int) floor($y / $blockHeight);
} else {
Expand All @@ -150,7 +150,7 @@ private function uneven(Image $image)
$weightLeft = (1 - $xFrac);
$weightRight = $xFrac;

// $xInt will be 0 on bottom/right borders and on block boundaries
// xInt will be 0 on bottom/right borders and on block boundaries.
if ($xInt > 0 || ($x + 1) === $imageWidth) {
$blockLeft = $blockRight = (int) floor($x / $blockWidth);
} else {
Expand All @@ -159,7 +159,7 @@ private function uneven(Image $image)
}
}

// add weighted pixel value to relevant blocks
// Add weighted pixel value to relevant blocks.
$blocks[$blockTop][$blockLeft] += $value * $weightTop * $weightLeft;
$blocks[$blockTop][$blockRight] += $value * $weightTop * $weightRight;
$blocks[$blockBottom][$blockLeft] += $value * $weightBottom * $weightLeft;
Expand All @@ -186,7 +186,7 @@ protected function blocksToBits(array $blocks, $pixelsPerBlock)
{
$halfBlockValue = $pixelsPerBlock * 256 * 3 / 2;

// Compare medians across four horizontal bands
// Compare medians across four horizontal bands.
$bandsize = (int) floor(count($blocks) / 4);

$bits = [];
Expand All @@ -202,7 +202,7 @@ protected function blocksToBits(array $blocks, $pixelsPerBlock)
// end up being 0 or the max value, and thus having a lot
// of blocks of value equal to the median. To avoid
// generating hashes of all zeros or ones, in that case output
// 0 if the median is in the lower value space, 1 otherwise
// 0 if the median is in the lower value space, 1 otherwise.
$bits[$j] = (int) ($value > $median || (abs($value - $median) < 1 && $median > $halfBlockValue));
}
}
Expand Down

0 comments on commit d1188fe

Please sign in to comment.