Created
September 6, 2023 15:29
-
-
Save Northernside/a052055d9f78d69297c06be4a6723aac to your computer and use it in GitHub Desktop.
dHashing in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Jimp from "jimp"; | |
export async function getDHash(skin) { | |
skin.grayscale(); | |
skin.resize(8, 9); | |
let dHash = ""; | |
for (let y = 0; y < 9; y++) { | |
let rowHash = 0; | |
for (let x = 0; x < 8 - 1; x++) { | |
const leftPixel = Jimp.intToRGBA(skin.getPixelColor(x, y)).r; | |
const rightPixel = Jimp.intToRGBA(skin.getPixelColor(x + 1, y)).r; | |
rowHash = (rowHash << 1) | (leftPixel > rightPixel ? 1 : 0); | |
} | |
dHash += rowHash.toString(16); | |
} | |
return dHash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment