Skip to content

Instantly share code, notes, and snippets.

@Northernside
Created September 6, 2023 15:29
Show Gist options
  • Save Northernside/a052055d9f78d69297c06be4a6723aac to your computer and use it in GitHub Desktop.
Save Northernside/a052055d9f78d69297c06be4a6723aac to your computer and use it in GitHub Desktop.
dHashing in Node.js
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