koishi-plugin-jryspro-fast 2.2.3 → 2.2.5
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/index.js +15 -27
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -270,23 +270,12 @@ async function apply(ctx, config) {
|
|
|
270
270
|
}
|
|
271
271
|
});
|
|
272
272
|
async function htmlToImg(html, width, height) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
{
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
|
-
if (config.imgQuality === 100) {
|
|
282
|
-
return await ctx.toImageService.svgToImage.vips(svg, {
|
|
283
|
-
format: "png"
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
return await ctx.toImageService.svgToImage.vips(svg, {
|
|
287
|
-
format: "jpeg",
|
|
288
|
-
options: {
|
|
289
|
-
Q: config.imgQuality
|
|
273
|
+
return await ctx.toImageService.htmlToImage(html, {
|
|
274
|
+
width,
|
|
275
|
+
height,
|
|
276
|
+
...config.imgQuality === 100 ? {} : {
|
|
277
|
+
format: "jpeg",
|
|
278
|
+
quality: config.imgQuality
|
|
290
279
|
}
|
|
291
280
|
});
|
|
292
281
|
}
|
|
@@ -335,34 +324,33 @@ async function apply(ctx, config) {
|
|
|
335
324
|
throw "渲染失败,不知道发生了啥";
|
|
336
325
|
}
|
|
337
326
|
const imgType = await fileType.fileTypeFromBuffer(imgData);
|
|
338
|
-
const
|
|
327
|
+
const sharp = await ctx.toImageService.sharpRenderer.getSharp();
|
|
339
328
|
let img;
|
|
340
329
|
let metaData;
|
|
341
330
|
const touchImg = /* @__PURE__ */ __name(() => {
|
|
342
331
|
if (!img) {
|
|
343
|
-
img =
|
|
332
|
+
img = sharp(imgData);
|
|
344
333
|
}
|
|
345
334
|
}, "touchImg");
|
|
346
335
|
if (needMetadata) {
|
|
347
336
|
touchImg();
|
|
337
|
+
const metadata = await img.metadata();
|
|
348
338
|
metaData = {
|
|
349
|
-
width:
|
|
350
|
-
height:
|
|
339
|
+
width: metadata.width,
|
|
340
|
+
height: metadata.height
|
|
351
341
|
};
|
|
352
342
|
}
|
|
353
343
|
if (cover) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
crop: vips.Interesting.centre
|
|
357
|
-
});
|
|
344
|
+
touchImg();
|
|
345
|
+
img.resize(cover.width, cover.height);
|
|
358
346
|
if (imgType.ext !== "webp") {
|
|
359
|
-
imgData = Buffer.from(img.
|
|
347
|
+
imgData = Buffer.from(await img.toBuffer());
|
|
360
348
|
}
|
|
361
349
|
}
|
|
362
350
|
let mime = imgType.mime;
|
|
363
351
|
if (imgType.ext === "webp") {
|
|
364
352
|
touchImg();
|
|
365
|
-
imgData = Buffer.from(img.
|
|
353
|
+
imgData = Buffer.from(await img.png().toBuffer());
|
|
366
354
|
mime = "image/png";
|
|
367
355
|
}
|
|
368
356
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-jryspro-fast",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
6
6
|
"homepage": "https://github.com/pgnqukezrdxmhjso/koishi-plugin-jryspro-fast",
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"file-type": "^21.3.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"koishi-plugin-to-image-service": "^0.1
|
|
58
|
+
"koishi-plugin-to-image-service": "^1.0.1"
|
|
59
59
|
}
|
|
60
60
|
}
|