# image-hash-2

> Create a hash from an image

Latest version **3.5.6** (published 2020-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install image-hash-2
pnpm add image-hash-2
yarn add image-hash-2
bun add image-hash-2
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.5.6 |
| Published | 2020-04-03 |
| First published | 2020-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Daniel Morrison |
| Maintainers | hooraygith |
| Keywords | phash, hash, image hash, perceptual hash |

## Links

- npm: https://www.npmjs.com/package/image-hash-2
- Repository: https://github.com/danm/image-hash
- Homepage: https://github.com/danm/image-hash#readme
- Issues: https://github.com/danm/image-hash/issues
- npm.io page: https://npm.io/package/image-hash-2

## Dependencies (4)

- [pngjs](https://npm.io/package/pngjs.md) ^3.3.3
- [jpeg-js](https://npm.io/package/jpeg-js.md) ^0.2.0
- [request](https://npm.io/package/request.md) ^2.81.0
- [file-type](https://npm.io/package/file-type.md) ^9.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 3.5.6 (latest) — 2020-04-03
- 3.5.5 — 2020-03-31
- 3.5.4 — 2020-03-31
- 3.5.3 — 2020-03-31
- 3.5.2 — 2020-03-31
- 3.5.1 — 2020-03-31
- 3.5.0 — 2020-03-31

## README

# image-hash
A wrapper around [block-hash](https://github.com/commonsmachinery/blockhash-js) to easily hash a local or remote file with Node.

Supports JPG and PNG

## Install
```bash
npm i -S image-hash
```

## Use
```javascript
const { imageHash }= require('image-hash');

// remote file simple
imageHash('https://ichef-1.bbci.co.uk/news/660/cpsprodpb/7F76/production/_95703623_mediaitem95703620.jpg', 16, true, (error, data) => {
  if (error) throw error;
  console.log(data);
  // 0773063f063f36070e070a070f378e7f1f000fff0fff020103f00ffb0f810ff0
});

// remote file with requestjs config object
const config = {
  uri: 'https://ichef-1.bbci.co.uk/news/660/cpsprodpb/7F76/production/_95703623_mediaitem95703620.jpg'
};

imageHash(config, 16, true, (error, data) => {
  if (error) throw error;
  console.log(data);
  // 0773063f063f36070e070a070f378e7f1f000fff0fff020103f00ffb0f810ff0
});

//local file
imageHash('./_95695590_tv039055678.jpg', 16, true, (error, data) => {
  if (error) throw error;
  console.log(data);
  // 0773063f063f36070e070a070f378e7f1f000fff0fff020103f00ffb0f810ff0
});
```

## API
```
// name
imageHash(location, bits, precise, callback)

// types
imageHash(string|object, int, bool, function)
```

### Image-Hash Arguments

Argument | Type | Description | Mandatory | Example
--- | --- | --- | --- | ---
location | `object` or `string` | A [RequestJS Object](https://github.com/request/request#requestoptions-callback) or `String` with a valid url or file location | Yes | see above
bits | `int` | The number of bits in a row. The more bits, the more unique the hash. | Yes | 8
precise | `bool` | Whether a precision algorithm is used. `true` Precise but slower, non-overlapping blocks. `false` Quick and crude, non-overlapping blocks. Method 2 is recommended as a good tradeoff between speed and good matches on any image size. The quick ones are only advisable when the image width and height are an even multiple of the number of blocks used. | Yes | `true`
callback | `function` | A function with `error` and `data` arguments - see below |  

### Callback Arguments

Argument | Type | Description
--- | --- | --- | --- | ---
error | `Error Object` or `null` | If a run time error is detected this will be an `Error Object`, otherwise `null`
data | `string` or `null` | If there is no run time error, this be will be your hashed result, otherwise `null` 

## Development
I have made this with Typescript, ESLint, Jest, Babel and VSCode. All config files and global binaries are included. For developers using VS Code, make sure you have ESLint extension installed.

## Testing
`npm test`

## Credit

The hard bit of this comes with thanks from [commonsmachinery](https://github.com/commonsmachinery) for [blockhash-js](https://github.com/commonsmachinery/blockhash-js)

## License

Distributed under an MIT license

---
_Source: https://npm.io/package/image-hash-2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
