@blocklet/images 1.16.37-beta-20241227-230028-f4f77779 → 1.16.37-beta-20250104-120451-e4049aeb

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.
Files changed (2) hide show
  1. package/lib/blurhash.js +12 -2
  2. package/package.json +3 -2
package/lib/blurhash.js CHANGED
@@ -9,14 +9,24 @@ const jimp_1 = require("jimp");
9
9
  const utils_1 = require("@jimp/utils");
10
10
  const blurhash_1 = require("blurhash");
11
11
  const image_type_1 = __importDefault(require("image-type"));
12
+ const is_svg_1 = __importDefault(require("is-svg"));
13
+ const resvg_js_1 = require("@resvg/resvg-js");
12
14
  async function getBlurhash(filePath) {
13
15
  if (!fs_1.default.existsSync(filePath)) {
14
16
  throw new Error(`File not found: ${filePath}`);
15
17
  }
16
- const buffer = fs_1.default.readFileSync(filePath);
18
+ let buffer = fs_1.default.readFileSync(filePath);
17
19
  const type = (0, image_type_1.default)(buffer);
18
20
  if (!type) {
19
- throw new Error(`File is not a valid image: ${filePath}`);
21
+ // svg 转位图
22
+ if ((0, is_svg_1.default)(buffer)) {
23
+ const svg = buffer.toString('utf-8');
24
+ const resvg = new resvg_js_1.Resvg(svg);
25
+ buffer = resvg.render().asPng();
26
+ }
27
+ else {
28
+ throw new Error(`File is not a valid image: ${filePath}`);
29
+ }
20
30
  }
21
31
  // Read image using Jimp
22
32
  const image = await jimp_1.Jimp.read(buffer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/images",
3
- "version": "1.16.37-beta-20241227-230028-f4f77779",
3
+ "version": "1.16.37-beta-20250104-120451-e4049aeb",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "MIT",
@@ -38,6 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@jimp/utils": "^1.6.0",
41
+ "@resvg/resvg-js": "^2.6.2",
41
42
  "blurhash": "^2.0.5",
42
43
  "image-size": "^1.0.2",
43
44
  "image-type": "^4.1.0",
@@ -54,5 +55,5 @@
54
55
  "ts-node": "^10.9.1",
55
56
  "typescript": "^5.6.3"
56
57
  },
57
- "gitHead": "e56e0d8c525e18e6fc84fa6915a9d8cb710bb28f"
58
+ "gitHead": "b7b25187705d6a0ac07d3ff4ed3333bf7808120b"
58
59
  }