From 3007d13c85e375fe0e31bec29e7a3658116bc712 Mon Sep 17 00:00:00 2001 From: mrAceT Date: Thu, 1 Apr 2021 21:15:34 +0200 Subject: [PATCH 1/2] Update dhash.php --- dhash.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dhash.php b/dhash.php index 40e3e37..7b74158 100644 --- a/dhash.php +++ b/dhash.php @@ -1,5 +1,6 @@ default, crop = 1 => skip the outer pixels, effectively cropping the thumb (remove border noise!) +function dhash($fname, $crop = 0, $onlyJPG = true) { // load exif thumbnail if possible; otherwise- load the image $thumb = exif_thumbnail($fname, $wid, $hei); @@ -11,21 +12,21 @@ function dhash($fname, $onlyJPG = true) unset($thumb); } // resize to 9x8 = 72 pixels, apply grayscale - $img = imagecreatetruecolor(9, 8); - imagecopyresampled($img, $src, 0, 0, 0, 0, 9, 8, $wid, $hei); + $img = imagecreatetruecolor(9+$crop*2, 8+$crop*2); + imagecopyresampled($img, $src, 0, 0, 0, 0, 9+$crop*2, 8+$crop*2, $wid, $hei); imagedestroy($src); imagefilter($img, IMG_FILTER_GRAYSCALE); //calculate dHash (hackerfactor.com/blog/?/archives/529-Kind-of-Like-That.html) $hash = 0; $bit = 1; - for ($y=0; $y<8; $y++) { + for ($y=0+$crop; $y<8; $y++) { if ($y == 4) { //second half of the image, this whole IF can be removed on 64bit machines $res = sprintf("%08x", $hash); $hash = 0; $bit = 1; } $previous = imagecolorat($img, 0, $y) & 0xFF; - for ($x=1; $x<9; $x++) { + for ($x=1+$crop; $x<9; $x++) { $current = imagecolorat($img, $x, $y) & 0xFF; if ($previous > $current) { $hash |= $bit; From 8792b79e6643f4f85e58defb3ca5db7a74517129 Mon Sep 17 00:00:00 2001 From: mrAceT Date: Fri, 2 Apr 2021 10:30:03 +0200 Subject: [PATCH 2/2] added crop option (note) --- dhash.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhash.php b/dhash.php index 7b74158..f8eef2d 100644 --- a/dhash.php +++ b/dhash.php @@ -1,4 +1,4 @@ - default, crop = 1 => skip the outer pixels, effectively cropping the thumb (remove border noise!) function dhash($fname, $crop = 0, $onlyJPG = true) {