friendly-img-hash-js 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,32 +1,41 @@
1
- import { hash as coreHash } from 'img-hash-js-core';
2
1
  import fs from 'fs';
3
- import imageType from 'image-type';
4
- import { PNG } from 'pngjs';
5
- import jpeg from 'jpeg-js';
2
+ import { hash as coreHash } from 'img-hash-js-core';
3
+
6
4
  import bmp from 'bmp-js';
5
+ import imageType from 'image-type';
6
+ import sharp from 'sharp';
7
7
  import UTIF from 'utif2';
8
8
 
9
- import { avif, webp } from '@astropub/codecs';
10
-
11
- import { getUrlData, isUrl } from './src/url-resolver.js';
12
9
  import { reduceToRgb } from './src/byte-resolver.js';
10
+ import { getUrlData, isUrl } from './src/url-resolver.js';
13
11
 
14
12
  export {
15
- Grayscale, Resize, Dct, Hash, Convert,
13
+ Convert, Dct, Grayscale, Hash, Resize,
16
14
  } from 'img-hash-js-core';
17
15
 
16
+ const sharpDecode = async (rawFileData) => {
17
+ const { data, info } = await sharp(rawFileData)
18
+ .resize(1920, null, { withoutEnlargement: true })
19
+ .raw()
20
+ .toBuffer({ resolveWithObject: true });
21
+ // Don't worry, Uint8 doesn't copy the buffer. It just wraps it.
22
+ return { ...info, data: new Uint8ClampedArray(data.buffer) };
23
+ };
24
+
18
25
  const extToResolver = {
19
- png: PNG.sync.read,
20
- jpg: jpeg.decode,
21
- bmp: bmp.decode,
26
+ png: sharpDecode,
27
+ svg: sharpDecode,
28
+ jpg: sharpDecode,
29
+ gif: sharpDecode,
30
+ webp: sharpDecode,
31
+ avif: sharpDecode,
22
32
  tif: (raw) => {
23
33
  const ifds = UTIF.decode(raw);
24
34
  UTIF.decodeImage(raw, ifds[0]);
25
35
  const rgba = UTIF.toRGBA8(ifds[0]); // Uint8Array with RGBA pixels
26
36
  return { data: rgba, width: ifds[0].width, height: ifds[0].height };
27
37
  },
28
- webp: webp.decode,
29
- avif: avif.decode,
38
+ bmp: bmp.decode,
30
39
  };
31
40
 
32
41
  // Hash an image!
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "friendly-img-hash-js",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "User friendly algorithms for generating image hashes.",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "test": "mocha index.test.js",
8
+ "test": "mocha src/**/*.test.js index.test.js",
9
9
  "lint": "eslint src/** index.js index.test.js --no-error-on-unmatched-pattern",
10
10
  "lint:fix": "eslint src/** index.js index.test.js --fix"
11
11
  },
@@ -37,12 +37,10 @@
37
37
  "mocha": "^10.2.0"
38
38
  },
39
39
  "dependencies": {
40
- "@astropub/codecs": "^0.4.4",
41
40
  "bmp-js": "^0.1.0",
42
- "image-type": "^5.2.0",
41
+ "image-type": "^6.0.0",
43
42
  "img-hash-js-core": "^1.0.7",
44
- "jpeg-js": "^0.4.4",
45
- "pngjs": "^7.0.0",
43
+ "sharp": "^0.34.4",
46
44
  "utif2": "^4.1.0"
47
45
  },
48
46
  "browser": "browser.js"
@@ -3,9 +3,8 @@ import https from 'https';
3
3
 
4
4
  export const isUrl = (s) => {
5
5
  try {
6
- // eslint-disable-next-line no-new
7
- new URL(s);
8
- return true;
6
+ const url = new URL(s);
7
+ return url.protocol.startsWith('http');
9
8
  } catch (err) {
10
9
  // Nope.
11
10
  }
@@ -1,13 +0,0 @@
1
- diff --git a/node_modules/react-native-libwebpjs/package.json b/node_modules/react-native-libwebpjs/package.json
2
- old mode 100644
3
- new mode 100755
4
- index 2bb6d59..f7cf399
5
- --- a/node_modules/react-native-libwebpjs/package.json
6
- +++ b/node_modules/react-native-libwebpjs/package.json
7
- @@ -1,5 +1,6 @@
8
- {
9
- "name": "react-native-libwebpjs",
10
- + "type": "module",
11
- "version": "1.0.0",
12
- "main": "libwebp.js",
13
- "description": "A forked libwebpjs-v0.6.0 for React Native"