Skip to content

Instantly share code, notes, and snippets.

@v-stickykeys
Last active January 3, 2021 20:00
Show Gist options
  • Save v-stickykeys/0fcc1d578c20837c8fbddaa2b9f28a50 to your computer and use it in GitHub Desktop.
Save v-stickykeys/0fcc1d578c20837c8fbddaa2b9f28a50 to your computer and use it in GitHub Desktop.
Node.js script to get an image hash
const { imageHash } = require('image-hash')
const image_url = 'https://media-exp1.licdn.com/dms/image/C4E03AQHTR_sKct2nmQ/profile-displayphoto-shrink_400_400/0/1594060729957?e=1613606400&v=beta&t=qVd6Yatw3WjkiVeo9ouKnC8h2lLbefQm6HROcxYE4Yc'
const bits = 16 // the more bits, the more unique the hash
const precise = true
async function main() {
const prom = new Promise((resolve, reject) => {
imageHash(image_url, bits, precise, (error, data) => {
if (error) reject(error)
else resolve(data)
})
})
const hash = await prom
console.log('Complete!')
console.log('Image hash:', hash)
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error)
process.exit(1)
})
{
"name": "photo-cred-app",
"version": "0.0.1",
"description": "Cryptographic signature of digital assets",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "val",
"license": "MIT",
"dependencies": {
"image-hash": "^4.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment