@blocklet/images 1.16.34-beta-20241126-120125-d0907434 → 1.16.34-beta-20241129-100152-679bd732
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/lib/blurhash.d.ts +1 -0
- package/lib/blurhash.js +37 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +6 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getBlurhash(filePath: string): Promise<string>;
|
package/lib/blurhash.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getBlurhash = getBlurhash;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const jimp_1 = require("jimp");
|
|
9
|
+
const utils_1 = require("@jimp/utils");
|
|
10
|
+
const blurhash_1 = require("blurhash");
|
|
11
|
+
const image_type_1 = __importDefault(require("image-type"));
|
|
12
|
+
async function getBlurhash(filePath) {
|
|
13
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
14
|
+
throw new Error(`File not found: ${filePath}`);
|
|
15
|
+
}
|
|
16
|
+
const buffer = fs_1.default.readFileSync(filePath);
|
|
17
|
+
const type = (0, image_type_1.default)(buffer);
|
|
18
|
+
if (!type) {
|
|
19
|
+
throw new Error(`File is not a valid image: ${filePath}`);
|
|
20
|
+
}
|
|
21
|
+
// Read image using Jimp
|
|
22
|
+
const image = await jimp_1.Jimp.read(buffer);
|
|
23
|
+
const { width, height } = image.bitmap;
|
|
24
|
+
// Convert image data to RGBA array
|
|
25
|
+
const pixels = new Uint8ClampedArray(width * height * 4);
|
|
26
|
+
// Scan through each pixel and add to array
|
|
27
|
+
image.scan(0, 0, width, height, (x, y) => {
|
|
28
|
+
const pixelIndex = (y * width + x) * 4;
|
|
29
|
+
const rgba = (0, utils_1.intToRGBA)(image.getPixelColor(x, y));
|
|
30
|
+
pixels[pixelIndex] = rgba.r;
|
|
31
|
+
pixels[pixelIndex + 1] = rgba.g;
|
|
32
|
+
pixels[pixelIndex + 2] = rgba.b;
|
|
33
|
+
pixels[pixelIndex + 3] = rgba.a;
|
|
34
|
+
});
|
|
35
|
+
const blurhash = (0, blurhash_1.encode)(pixels, width, height, 4, 4);
|
|
36
|
+
return blurhash;
|
|
37
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { validateLogo } from './logo-validate';
|
|
2
2
|
import { validateScreenshots } from './screenshot-validate';
|
|
3
3
|
import { ordinalSuffix } from './ordinal-suffix';
|
|
4
|
-
|
|
4
|
+
import { getBlurhash } from './blurhash';
|
|
5
|
+
export { validateLogo, validateScreenshots, ordinalSuffix, getBlurhash };
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ordinalSuffix = exports.validateScreenshots = exports.validateLogo = void 0;
|
|
3
|
+
exports.getBlurhash = exports.ordinalSuffix = exports.validateScreenshots = exports.validateLogo = void 0;
|
|
4
4
|
const logo_validate_1 = require("./logo-validate");
|
|
5
5
|
Object.defineProperty(exports, "validateLogo", { enumerable: true, get: function () { return logo_validate_1.validateLogo; } });
|
|
6
6
|
const screenshot_validate_1 = require("./screenshot-validate");
|
|
7
7
|
Object.defineProperty(exports, "validateScreenshots", { enumerable: true, get: function () { return screenshot_validate_1.validateScreenshots; } });
|
|
8
8
|
const ordinal_suffix_1 = require("./ordinal-suffix");
|
|
9
9
|
Object.defineProperty(exports, "ordinalSuffix", { enumerable: true, get: function () { return ordinal_suffix_1.ordinalSuffix; } });
|
|
10
|
+
const blurhash_1 = require("./blurhash");
|
|
11
|
+
Object.defineProperty(exports, "getBlurhash", { enumerable: true, get: function () { return blurhash_1.getBlurhash; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/images",
|
|
3
|
-
"version": "1.16.34-beta-
|
|
3
|
+
"version": "1.16.34-beta-20241129-100152-679bd732",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,9 +37,12 @@
|
|
|
37
37
|
"watch": "nodemon -w src -e ts -x 'npm run build'"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@jimp/utils": "^1.6.0",
|
|
41
|
+
"blurhash": "^2.0.5",
|
|
40
42
|
"image-size": "^1.0.2",
|
|
41
43
|
"image-type": "^4.1.0",
|
|
42
|
-
"is-svg": "^4.3.2"
|
|
44
|
+
"is-svg": "^4.3.2",
|
|
45
|
+
"jimp": "^1.6.0"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
@@ -51,5 +54,5 @@
|
|
|
51
54
|
"ts-node": "^10.9.1",
|
|
52
55
|
"typescript": "^5.6.3"
|
|
53
56
|
},
|
|
54
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "eb4b66b66af715559402fea679fe15b2a19cce2f"
|
|
55
58
|
}
|