{"id":21146466,"url":"https://github.com/pwlmaciejewski/imghash","last_synced_at":"2025-04-05T14:10:00.560Z","repository":{"id":3988545,"uuid":"51590968","full_name":"pwlmaciejewski/imghash","owner":"pwlmaciejewski","description":"Perceptual image hashing for Node.js","archived":false,"fork":false,"pushed_at":"2023-01-25T04:03:58.000Z","size":916,"stargazers_count":163,"open_issues_count":16,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-14T14:22:05.737Z","etag":null,"topics":["computer-vision","image-processing","imghash","webscraping"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pwlmaciejewski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-12T14:03:21.000Z","updated_at":"2024-04-13T18:48:33.000Z","dependencies_parsed_at":"2023-02-14T04:25:22.351Z","dependency_job_id":null,"html_url":"https://github.com/pwlmaciejewski/imghash","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwlmaciejewski%2Fimghash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwlmaciejewski%2Fimghash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwlmaciejewski%2Fimghash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwlmaciejewski%2Fimghash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwlmaciejewski","download_url":"https://codeload.github.com/pwlmaciejewski/imghash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345856,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","image-processing","imghash","webscraping"],"created_at":"2024-11-20T08:54:43.037Z","updated_at":"2025-04-05T14:10:00.542Z","avatar_url":"https://github.com/pwlmaciejewski.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# imghash ![build](https://github.com/pwlmaciejewski/imghash/workflows/Node.js%20CI/badge.svg) ![npm](https://img.shields.io/npm/v/imghash) ![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/pwlmaciejewski/imghash) ![NPM](https://img.shields.io/npm/l/imghash) \nPromise-based image perceptual hash calculation for node.\n\n## Installation\n\n```\nnpm install imghash\n```\n\n:information_source: You can find the command-line interface [here](https://github.com/pwlmaciejewski/imghash-cli).\n\n## Basic usage\n\n```js\nconst imghash = require(\"imghash\");\n\nconst hash1 = await imghash.hash(\"./path/to/file\");\nconsole.log(hash1);  // \"f884c4d8d1193c07\"\n\n// Custom hex length and result in binary\nconst hash2 = await imghash.hash(\"./path/to/file\", 4, \"binary\");\nconsole.log(hash2);  // \"1000100010000010\"\n```\n\n## Finding similar images\n\nTo measure similarity between images you can use [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) or [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance). \n\nThe following example uses the latter one:\n\n```js\nconst imghash = require(\"imghash\");\nconst leven = require(\"leven\");\n\nconst hash1 = await imghash.hash(\"./img1\");\nconst hash2 = await imghash.hash(\"./img2\");\n\nconst distance = leven(hash1, hash2);\nconsole.log(`Distance between images is: ${distance}`);\nif (distance \u003c= 12) {\n  console.log(\"Images are similar\");\n} else {\n  console.log(\"Images are NOT similar\");\n}\n```\n\n## API\n\n##### `.hash(filepath[, bits][, format])`\n\nReturns: ES6 `Promise`, resolved returns hash string in specified format and length (eg. `f884c4d8d1193c07`)\n\nParameters:\n\n* `filepath` - path to the image (supported formats are `png` and `jpeg`) or `Buffer`\n* `bits` (optional) - hash length [default: `8`]\n* `format` (optional) - output format [default: `hex`]\n\n---\n\n##### `.hashRaw(data, bits)`\n\nReturns: hex hash\n\nParameters:\n\n* `data` - image data descriptor in form `{ width: [width], height: [height], data: [decoded image pixels] }`\n* `bits` - hash length\n\n---\n\n##### `.hexToBinary(s)`\n\nReturns: hex string, eg. `f884c4d8d1193c07`.\n\nParameters:\n\n* `s` - binary hash string eg. `1000100010000010`\n\n---\n\n##### `.binaryToHex(s)`\n\nReturns: hex string, eg. `1000100010000010`.\n\nParameters:\n\n* `s` - hex hash string eg. `f884c4d8d1193c07`\n\n## Further reading\n\n`imghash` takes advantage of block mean value based hashing method:\n\n* [http://stackoverflow.com/questions/14377854/block-mean-value-hashing-method](http://stackoverflow.com/questions/14377854/block-mean-value-hashing-method)\n* [http://commonsmachinery.se/2014/09/digital-image-matching-part-1-hashing/](http://commonsmachinery.se/2014/09/digital-image-matching-part-1-hashing/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwlmaciejewski%2Fimghash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwlmaciejewski%2Fimghash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwlmaciejewski%2Fimghash/lists"}