@pi-r/jimp 0.6.9 → 0.6.10
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/package.json +3 -3
- package/worker/jimp.js +63 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/jimp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "Jimp image constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/image": "^0.8.
|
|
24
|
-
"@e-mc/types": "^0.8.
|
|
23
|
+
"@e-mc/image": "^0.8.29",
|
|
24
|
+
"@e-mc/types": "^0.8.29",
|
|
25
25
|
"bmp-js": "^0.1.0",
|
|
26
26
|
"gifwrap": "^0.10.1",
|
|
27
27
|
"jimp": "^0.22.12"
|
package/worker/jimp.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
+
const { Jimp } = require('jimp');
|
|
5
|
+
const Image = require('@e-mc/image');
|
|
6
|
+
const { errorMessage, isString } = require('@e-mc/types');
|
|
7
|
+
const Main = require('@pi-r/jimp');
|
|
8
|
+
const PORT = workerData[0];
|
|
9
|
+
parentPort.on('message', (value) => {
|
|
10
|
+
const { data, commandData, output, options } = value;
|
|
11
|
+
Jimp.read(typeof data === 'string' ? data : Image.asBuffer(data))
|
|
12
|
+
.then(async (img) => {
|
|
13
|
+
const { method, resize, crop, rotate, opacity = -1 } = commandData;
|
|
14
|
+
if (method) {
|
|
15
|
+
for (const [name, args = []] of method) {
|
|
16
|
+
if (name === 'composite') {
|
|
17
|
+
const [src, x, y, opts] = args;
|
|
18
|
+
if (isString(src) && typeof x === 'number' && typeof y === 'number') {
|
|
19
|
+
img.composite(await Jimp.read(src), x, y, opts);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw errorMessage(name, "Invalid parameters", JSON.stringify(value));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
Main.applyMethod(img, name, ...args);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (resize) {
|
|
31
|
+
Main.applyResize(img, resize);
|
|
32
|
+
}
|
|
33
|
+
if (crop) {
|
|
34
|
+
Main.applyCrop(img, crop);
|
|
35
|
+
}
|
|
36
|
+
if (rotate) {
|
|
37
|
+
Main.applyRotate(img, rotate);
|
|
38
|
+
}
|
|
39
|
+
if (opacity >= 0) {
|
|
40
|
+
img.opacity(opacity);
|
|
41
|
+
}
|
|
42
|
+
if (output) {
|
|
43
|
+
img.write(output, options)
|
|
44
|
+
.then(() => {
|
|
45
|
+
PORT.postMessage(output);
|
|
46
|
+
})
|
|
47
|
+
.catch((err) => {
|
|
48
|
+
console.error(err);
|
|
49
|
+
PORT.postMessage(null);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
void img.getBuffer(value.outputType, options)
|
|
54
|
+
.then(result => {
|
|
55
|
+
PORT.postMessage(result, [result.buffer]);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.catch((err) => {
|
|
60
|
+
console.error(err);
|
|
61
|
+
PORT.postMessage(null);
|
|
62
|
+
});
|
|
63
|
+
});
|