@pi-r/jimp 0.6.10 → 0.6.11
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 +1 -1
- package/worker/jimp.js +0 -63
package/package.json
CHANGED
package/worker/jimp.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
});
|