@pi-r/jimp 0.3.4 → 0.3.6
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/LICENSE +6 -6
- package/README.md +4 -6
- package/index.js +162 -194
- package/package.json +29 -29
- package/types/index.d.ts +18 -18
- package/util.d.ts +9 -9
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -30,16 +30,13 @@ const METHOD_ALIAS = {
|
|
|
30
30
|
composite: 'cp',
|
|
31
31
|
mask: 'ma',
|
|
32
32
|
convolute: 'cl',
|
|
33
|
-
convolution: 'cl',
|
|
34
33
|
flip: 'fl',
|
|
35
34
|
mirror: 'mi',
|
|
36
35
|
rotate: 'ro',
|
|
37
36
|
brightness: 'br',
|
|
38
37
|
contrast: 'cn',
|
|
39
38
|
dither565: 'dt',
|
|
40
|
-
dither16: 'dt',
|
|
41
39
|
greyscale: 'gr',
|
|
42
|
-
grayscale: 'gr',
|
|
43
40
|
invert: 'in',
|
|
44
41
|
normalize: 'no',
|
|
45
42
|
fade: 'fa',
|
|
@@ -52,32 +49,20 @@ const METHOD_ALIAS = {
|
|
|
52
49
|
sepia: 'se',
|
|
53
50
|
pixelate: 'px',
|
|
54
51
|
displace: 'dp',
|
|
55
|
-
color: 'co'
|
|
56
|
-
colour: 'co',
|
|
57
|
-
backgroundQuiet: 'bq',
|
|
58
|
-
circle: 'ci',
|
|
59
|
-
colorType: 'ce',
|
|
60
|
-
cropQuiet: 'cq',
|
|
61
|
-
deflateLevel: 'dl',
|
|
62
|
-
deflateStrategy: 'ds',
|
|
63
|
-
fishEye: 'fe',
|
|
64
|
-
filterType: 'ft',
|
|
65
|
-
rgba: 'rg',
|
|
66
|
-
shadow: 'sh',
|
|
67
|
-
threshold: 'th'
|
|
52
|
+
color: 'co'
|
|
68
53
|
};
|
|
69
54
|
function getMethodName(value) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return name;
|
|
73
|
-
}
|
|
74
|
-
if (name.length === 2) {
|
|
55
|
+
if (value.length === 2) {
|
|
56
|
+
value = value.toLowerCase();
|
|
75
57
|
for (const alias in METHOD_ALIAS) {
|
|
76
|
-
if (METHOD_ALIAS[alias] ===
|
|
58
|
+
if (METHOD_ALIAS[alias] === value) {
|
|
77
59
|
return alias;
|
|
78
60
|
}
|
|
79
61
|
}
|
|
80
62
|
}
|
|
63
|
+
else if (METHOD_ALIAS[value] || METHOD_ALIAS[value = value.toLowerCase()]) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
81
66
|
}
|
|
82
67
|
function performCommand(host, instance, localUri, command, outputType, finalAs, buffer, parent) {
|
|
83
68
|
return jimp.read((buffer || localUri))
|
|
@@ -85,21 +70,6 @@ function performCommand(host, instance, localUri, command, outputType, finalAs,
|
|
|
85
70
|
return transformCommand(localUri, new JimpHandler(img, instance, host), command, outputType, finalAs, parent);
|
|
86
71
|
});
|
|
87
72
|
}
|
|
88
|
-
function execOptions(settings) {
|
|
89
|
-
var _a;
|
|
90
|
-
const exec = (_a = settings.jimp) === null || _a === void 0 ? void 0 : _a.exec;
|
|
91
|
-
let uid, gid;
|
|
92
|
-
if ((0, types_1.isPlainObject)(exec)) {
|
|
93
|
-
let { uid: u, gid: g } = exec;
|
|
94
|
-
if ((u = parseInt(u)) >= 0) {
|
|
95
|
-
uid = u;
|
|
96
|
-
}
|
|
97
|
-
if ((g = parseInt(g)) >= 0) {
|
|
98
|
-
gid = g;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return { uid, gid };
|
|
102
|
-
}
|
|
103
73
|
async function transformCommand(localFile, handler, command, outputType, outputAs, parent) {
|
|
104
74
|
if (command) {
|
|
105
75
|
handler.instance.setCommand(command, outputAs);
|
|
@@ -107,11 +77,13 @@ async function transformCommand(localFile, handler, command, outputType, outputA
|
|
|
107
77
|
await handler.method();
|
|
108
78
|
handler.resize();
|
|
109
79
|
handler.crop();
|
|
110
|
-
if (outputType
|
|
111
|
-
|
|
80
|
+
if (outputType === jimp.MIME_JPEG) {
|
|
81
|
+
if (!outputAs) {
|
|
82
|
+
handler.quality();
|
|
83
|
+
}
|
|
112
84
|
}
|
|
113
|
-
else
|
|
114
|
-
handler.
|
|
85
|
+
else {
|
|
86
|
+
handler.opacity();
|
|
115
87
|
}
|
|
116
88
|
switch (handler.rotateCount) {
|
|
117
89
|
case 0:
|
|
@@ -121,9 +93,9 @@ async function transformCommand(localFile, handler, command, outputType, outputA
|
|
|
121
93
|
default:
|
|
122
94
|
return handler.rotate(localFile, (err, result) => {
|
|
123
95
|
var _a;
|
|
124
|
-
if (!err
|
|
96
|
+
if (!err) {
|
|
125
97
|
try {
|
|
126
|
-
handler.host.add(result, parent);
|
|
98
|
+
(_a = handler.host) === null || _a === void 0 ? void 0 : _a.add(result, parent);
|
|
127
99
|
}
|
|
128
100
|
catch {
|
|
129
101
|
}
|
|
@@ -283,32 +255,31 @@ class JimpHandler {
|
|
|
283
255
|
return;
|
|
284
256
|
}
|
|
285
257
|
const data = this.instance.methodData;
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
258
|
+
if (data) {
|
|
259
|
+
const handler = this.handler;
|
|
260
|
+
for (const [name, args = []] of data) {
|
|
261
|
+
try {
|
|
262
|
+
const alias = getMethodName(name);
|
|
263
|
+
if (!alias) {
|
|
264
|
+
throw (0, types_1.errorValue)("Invalid method name", name);
|
|
265
|
+
}
|
|
266
|
+
if (alias === 'composite') {
|
|
267
|
+
const [src, x, y, opts] = args;
|
|
268
|
+
if ((0, types_1.isString)(src) && typeof x === 'number' && typeof y === 'number') {
|
|
269
|
+
handler.composite(await jimp.read(src), x, y, opts);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
throw (0, types_1.errorValue)("Invalid parameters", alias);
|
|
273
|
+
}
|
|
300
274
|
}
|
|
301
275
|
else {
|
|
302
|
-
|
|
276
|
+
handler[alias](...args);
|
|
303
277
|
}
|
|
304
278
|
}
|
|
305
|
-
|
|
306
|
-
|
|
279
|
+
catch (err) {
|
|
280
|
+
this.instance.writeFail(["Unknown", "jimp" + ': ' + name], err, 2048);
|
|
307
281
|
}
|
|
308
282
|
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
this.instance.writeFail(["Unknown", "jimp" + ': ' + name], err, 2048);
|
|
311
|
-
}
|
|
312
283
|
}
|
|
313
284
|
}
|
|
314
285
|
resize() {
|
|
@@ -316,64 +287,63 @@ class JimpHandler {
|
|
|
316
287
|
return;
|
|
317
288
|
}
|
|
318
289
|
const data = this.instance.resizeData;
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
break;
|
|
290
|
+
if (data) {
|
|
291
|
+
const { width, height, color, algorithm, align, mode } = data;
|
|
292
|
+
const handler = this.handler;
|
|
293
|
+
if (!isNaN(color)) {
|
|
294
|
+
handler.background(color);
|
|
295
|
+
}
|
|
296
|
+
let resizeMode = jimp.RESIZE_NEAREST_NEIGHBOR, flags = 0;
|
|
297
|
+
switch (algorithm) {
|
|
298
|
+
case 'bilinear':
|
|
299
|
+
resizeMode = jimp.RESIZE_BILINEAR;
|
|
300
|
+
break;
|
|
301
|
+
case 'bicubic':
|
|
302
|
+
resizeMode = jimp.RESIZE_BICUBIC;
|
|
303
|
+
break;
|
|
304
|
+
case 'hermite':
|
|
305
|
+
resizeMode = jimp.RESIZE_HERMITE;
|
|
306
|
+
break;
|
|
307
|
+
case 'bezier':
|
|
308
|
+
resizeMode = jimp.RESIZE_BEZIER;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
switch (align[0]) {
|
|
312
|
+
case 'left':
|
|
313
|
+
flags |= jimp.HORIZONTAL_ALIGN_LEFT;
|
|
314
|
+
break;
|
|
315
|
+
case 'center':
|
|
316
|
+
flags |= jimp.HORIZONTAL_ALIGN_CENTER;
|
|
317
|
+
break;
|
|
318
|
+
case 'right':
|
|
319
|
+
flags |= jimp.HORIZONTAL_ALIGN_RIGHT;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
switch (align[1]) {
|
|
323
|
+
case 'top':
|
|
324
|
+
flags |= jimp.VERTICAL_ALIGN_TOP;
|
|
325
|
+
break;
|
|
326
|
+
case 'middle':
|
|
327
|
+
flags |= jimp.VERTICAL_ALIGN_MIDDLE;
|
|
328
|
+
break;
|
|
329
|
+
case 'bottom':
|
|
330
|
+
flags |= jimp.VERTICAL_ALIGN_BOTTOM;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
switch (mode) {
|
|
334
|
+
case 'contain':
|
|
335
|
+
handler.contain(width, height, flags);
|
|
336
|
+
break;
|
|
337
|
+
case 'cover':
|
|
338
|
+
handler.cover(width, height, flags);
|
|
339
|
+
break;
|
|
340
|
+
case 'scale':
|
|
341
|
+
handler.scaleToFit(width, height);
|
|
342
|
+
break;
|
|
343
|
+
default:
|
|
344
|
+
handler.resize(width === Infinity ? jimp.AUTO : width, height === Infinity ? jimp.AUTO : height, resizeMode);
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
377
347
|
}
|
|
378
348
|
}
|
|
379
349
|
background(value) {
|
|
@@ -383,13 +353,13 @@ class JimpHandler {
|
|
|
383
353
|
this.handler.background(value);
|
|
384
354
|
}
|
|
385
355
|
finalize(output, callback) {
|
|
356
|
+
var _a;
|
|
386
357
|
if (this.aborted) {
|
|
387
358
|
return;
|
|
388
359
|
}
|
|
389
360
|
const instance = this.instance;
|
|
390
361
|
if (instance.outputAs === 'webp' && path.extname(output).toLowerCase() !== '.webp') {
|
|
391
|
-
const
|
|
392
|
-
const webp = settings.webp || (settings.webp = {});
|
|
362
|
+
const webp = (_a = instance.settings).webp || (_a.webp = {});
|
|
393
363
|
const data = instance.qualityData;
|
|
394
364
|
const replace = instance.getCommand().indexOf('@') !== -1;
|
|
395
365
|
const filename = (0, util_1.renameExt)(output, 'webp', replace);
|
|
@@ -436,7 +406,7 @@ class JimpHandler {
|
|
|
436
406
|
}
|
|
437
407
|
args.push('-o', (0, util_1.normalizePath)(filename));
|
|
438
408
|
try {
|
|
439
|
-
child_process.execFile((0, util_1.getWebP_bin)('cwebp', webp.path), args, { shell: true, signal: this.instance.signal
|
|
409
|
+
child_process.execFile((0, util_1.getWebP_bin)('cwebp', webp.path), args, { shell: true, signal: this.instance.signal }, err => {
|
|
440
410
|
if (err) {
|
|
441
411
|
this.instance.writeFail(["Unable to convert file", path.basename(filename)], err, 2048);
|
|
442
412
|
}
|
|
@@ -575,67 +545,67 @@ class Jimp extends Image {
|
|
|
575
545
|
static async transform(file, command, options = {}) {
|
|
576
546
|
const [outputType, saveAs, finalAs] = (0, util_1.parseFormat)(command = command.trim(), options.mimeType);
|
|
577
547
|
const empty = () => options.tempFile ? '' : null;
|
|
578
|
-
if (
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
548
|
+
if (outputType) {
|
|
549
|
+
const instance = new Jimp(options.module);
|
|
550
|
+
let buffer = null;
|
|
551
|
+
if (Buffer.isBuffer(file)) {
|
|
552
|
+
const tempDir = TEMP_DIR || instance.getTempDir();
|
|
553
|
+
if (!this.createDir(tempDir)) {
|
|
554
|
+
return empty();
|
|
555
|
+
}
|
|
556
|
+
try {
|
|
557
|
+
const { ext } = await this.resolveMime(file) || { ext: 'unknown' };
|
|
558
|
+
buffer = file;
|
|
559
|
+
fs.writeFileSync(file = path.join(tempDir, (0, types_1.generateUUID)() + '.' + ext), buffer);
|
|
560
|
+
}
|
|
561
|
+
catch {
|
|
562
|
+
return empty();
|
|
563
|
+
}
|
|
564
|
+
options.cache = false;
|
|
565
|
+
}
|
|
566
|
+
const filename = path.basename(file);
|
|
567
|
+
const broadcastId = options.broadcastId;
|
|
568
|
+
if (broadcastId) {
|
|
569
|
+
if ((0, types_1.isPlainObject)(broadcastId)) {
|
|
570
|
+
instance.broadcastId = broadcastId.value;
|
|
571
|
+
if (broadcastId.stripAnsi === false) {
|
|
572
|
+
instance.supports('stripAnsi', false);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
instance.broadcastId = broadcastId;
|
|
577
|
+
}
|
|
595
578
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
579
|
+
const writeMessage = (failed, cTimeMs) => {
|
|
580
|
+
if (cTimeMs || options.startTime) {
|
|
581
|
+
formatMessage.call(instance, filename + (0, util_1.showOutputType)(options.mimeType, outputType, finalAs), options.startTime, failed, cTimeMs);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
let tempKey, tempFile;
|
|
585
|
+
if (options.cache) {
|
|
586
|
+
let ctimeMs;
|
|
587
|
+
[buffer, tempFile, ctimeMs] = getImageCache.call(instance, tempKey = file + command + (options.mimeType || ''));
|
|
588
|
+
if (buffer) {
|
|
589
|
+
writeMessage(false, ctimeMs);
|
|
590
|
+
return Promise.resolve(buffer);
|
|
605
591
|
}
|
|
606
592
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
instance.formatMessage(Image.LOG_TYPE.IMAGE, "jimp", ["Transforming image...", filename], command);
|
|
626
|
-
Image.initCpuUsage(instance);
|
|
627
|
-
return performCommand(null, instance, file, command, outputType, finalAs)
|
|
628
|
-
.then(async (handler) => {
|
|
629
|
-
const result = await handler.getBuffer(options.tempFile, saveAs);
|
|
630
|
-
instance.flushLog();
|
|
631
|
-
writeMessage(!result || instance.errors.length > 0);
|
|
632
|
-
if (result && tempKey && tempFile) {
|
|
633
|
-
setImageCache.call(instance, tempKey, tempFile, result, file);
|
|
634
|
-
}
|
|
635
|
-
return result;
|
|
636
|
-
})
|
|
637
|
-
.catch(() => empty())
|
|
638
|
-
.finally(() => buffer && !options.cache && removeFile(file));
|
|
593
|
+
instance.formatMessage(Image.LOG_TYPE.IMAGE, "jimp", ["Transforming image...", filename], command);
|
|
594
|
+
Image.initCpuUsage(instance);
|
|
595
|
+
return performCommand(null, instance, file, command, outputType, finalAs)
|
|
596
|
+
.then(async (handler) => {
|
|
597
|
+
const result = await handler.getBuffer(options.tempFile, saveAs);
|
|
598
|
+
instance.flushLog();
|
|
599
|
+
writeMessage(!result || instance.errors.length > 0);
|
|
600
|
+
if (result && tempKey && tempFile) {
|
|
601
|
+
setImageCache.call(instance, tempKey, tempFile, result, file);
|
|
602
|
+
}
|
|
603
|
+
return result;
|
|
604
|
+
})
|
|
605
|
+
.catch(() => empty())
|
|
606
|
+
.finally(() => buffer && !options.cache && removeFile(file));
|
|
607
|
+
}
|
|
608
|
+
return empty();
|
|
639
609
|
}
|
|
640
610
|
parseRotate(value) {
|
|
641
611
|
var _a;
|
|
@@ -654,6 +624,7 @@ class Jimp extends Image {
|
|
|
654
624
|
}
|
|
655
625
|
return new Promise(async (resolve, reject) => {
|
|
656
626
|
var _a;
|
|
627
|
+
var _b;
|
|
657
628
|
const { host, file } = data;
|
|
658
629
|
const localUri = host.getLocalUri(data);
|
|
659
630
|
const mimeType = host.getMimeType(data);
|
|
@@ -683,9 +654,8 @@ class Jimp extends Image {
|
|
|
683
654
|
const startTime = process.hrtime();
|
|
684
655
|
const success = (result, ctimeMs) => {
|
|
685
656
|
const filename = path.basename(result);
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
host.writeImage(document, data.getObject({ command, output: result }));
|
|
657
|
+
if (file.document) {
|
|
658
|
+
host.writeImage(file.document, data.getObject({ command, output: result }));
|
|
689
659
|
}
|
|
690
660
|
if (host.getLocalUri(data) !== result) {
|
|
691
661
|
if (command.indexOf('%') !== -1) {
|
|
@@ -796,12 +766,11 @@ class Jimp extends Image {
|
|
|
796
766
|
const args = [(0, util_1.normalizePath)(target)];
|
|
797
767
|
const quality = cmd.quality;
|
|
798
768
|
if (quality) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
args.push('-q', value.toString());
|
|
769
|
+
if (!isNaN(quality.value)) {
|
|
770
|
+
args.push('-q', quality.value.toString());
|
|
802
771
|
}
|
|
803
|
-
if (!isNaN(method)) {
|
|
804
|
-
args.push('-m', method.toString());
|
|
772
|
+
if (!isNaN(quality.method)) {
|
|
773
|
+
args.push('-m', quality.method.toString());
|
|
805
774
|
}
|
|
806
775
|
}
|
|
807
776
|
if (Array.isArray(gif2webp)) {
|
|
@@ -830,7 +799,7 @@ class Jimp extends Image {
|
|
|
830
799
|
}
|
|
831
800
|
args.push('-o', (0, util_1.normalizePath)(webp));
|
|
832
801
|
try {
|
|
833
|
-
child_process.execFile((0, util_1.getWebP_bin)('gif2webp', webp_path), args, { shell: true, signal: this.signal
|
|
802
|
+
child_process.execFile((0, util_1.getWebP_bin)('gif2webp', webp_path), args, { shell: true, signal: this.signal }, (err, stdout) => {
|
|
834
803
|
if (!err) {
|
|
835
804
|
this.addLog(types_1.STATUS_TYPE.INFO, stdout);
|
|
836
805
|
finalize(webp);
|
|
@@ -975,11 +944,10 @@ class Jimp extends Image {
|
|
|
975
944
|
}
|
|
976
945
|
return false;
|
|
977
946
|
};
|
|
978
|
-
const
|
|
979
|
-
const { path: webp_path } = settings.webp || (settings.webp = {});
|
|
947
|
+
const { path: webp_path } = (_b = this.settings).webp || (_b.webp = {});
|
|
980
948
|
const bmpFile = getTempPath.call(this, 'bmp');
|
|
981
949
|
try {
|
|
982
|
-
child_process.execFile((0, util_1.getWebP_bin)('dwebp', webp_path), [(0, util_1.normalizePath)(localUri), '-bmp', '-o', (0, util_1.normalizePath)(bmpFile)], { shell: true, signal: this.signal
|
|
950
|
+
child_process.execFile((0, util_1.getWebP_bin)('dwebp', webp_path), [(0, util_1.normalizePath)(localUri), '-bmp', '-o', (0, util_1.normalizePath)(bmpFile)], { shell: true, signal: this.signal }, err => {
|
|
983
951
|
if (!err) {
|
|
984
952
|
transformBuffer(bmpFile);
|
|
985
953
|
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/jimp",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "Jimp image constructor for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/module/jimp"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"squared",
|
|
16
|
-
"e-mc",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/image": "^0.6.
|
|
24
|
-
"@e-mc/types": "^0.6.
|
|
25
|
-
"bmp-js": "^0.1.0",
|
|
26
|
-
"gifwrap": "^0.10.1",
|
|
27
|
-
"jimp": "^0.22.12"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/jimp",
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"description": "Jimp image constructor for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"directory": "src/module/jimp"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"squared",
|
|
16
|
+
"e-mc",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/image": "^0.6.16",
|
|
24
|
+
"@e-mc/types": "^0.6.16",
|
|
25
|
+
"bmp-js": "^0.1.0",
|
|
26
|
+
"gifwrap": "^0.10.1",
|
|
27
|
+
"jimp": "^0.22.12"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { IHost, IImage, ImageConstructor } from '@e-mc/types/lib';
|
|
2
|
-
import type { ImageModule } from '@e-mc/types/lib/settings';
|
|
3
|
-
|
|
4
|
-
import type { ImageHandler } from '@e-mc/image/types';
|
|
5
|
-
|
|
6
|
-
import type * as jimp from 'jimp';
|
|
7
|
-
|
|
8
|
-
export interface IJimpHandler<T extends IHost = IHost, U extends ImageModule = ImageModule> extends ImageHandler<jimp, T, IImage<T, U>> {
|
|
9
|
-
method(): Promise<void>;
|
|
10
|
-
rotate(localFile?: string, callback?: ResultCallback<string>): Promise<this>;
|
|
11
|
-
background(value: number | [number, number, number, number]): void;
|
|
12
|
-
writeAsync(output: string, callback?: ResultCallback): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface JimpImageConstructor extends ImageConstructor {
|
|
16
|
-
new(handler: jimp, instance: IImage, host?: Null<IHost>): IJimpHandler;
|
|
17
|
-
}
|
|
18
|
-
|
|
1
|
+
import type { IHost, IImage, ImageConstructor } from '@e-mc/types/lib';
|
|
2
|
+
import type { ImageModule } from '@e-mc/types/lib/settings';
|
|
3
|
+
|
|
4
|
+
import type { ImageHandler } from '@e-mc/image/types';
|
|
5
|
+
|
|
6
|
+
import type * as jimp from 'jimp';
|
|
7
|
+
|
|
8
|
+
export interface IJimpHandler<T extends IHost = IHost, U extends ImageModule = ImageModule> extends ImageHandler<jimp, T, IImage<T, U>> {
|
|
9
|
+
method(): Promise<void>;
|
|
10
|
+
rotate(localFile?: string, callback?: ResultCallback<string>): Promise<this>;
|
|
11
|
+
background(value: number | [number, number, number, number]): void;
|
|
12
|
+
writeAsync(output: string, callback?: ResultCallback): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface JimpImageConstructor extends ImageConstructor {
|
|
16
|
+
new(handler: jimp, instance: IImage, host?: Null<IHost>): IJimpHandler;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
19
|
export type ResultCallback<T = unknown, U = void, V = unknown> = (err: V, result: T) => U;
|
package/util.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
declare namespace util {
|
|
2
|
-
function parseFormat(command: string, mimeType?: string, gif?: boolean): [string, string, string];
|
|
3
|
-
function renameExt(output: string, ext: string, replace?: boolean): string;
|
|
4
|
-
function normalizePath(value: string): string;
|
|
5
|
-
function getWebP_bin(name: string, pathname: string | undefined): string;
|
|
6
|
-
function showInputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
7
|
-
function showOutputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
declare namespace util {
|
|
2
|
+
function parseFormat(command: string, mimeType?: string, gif?: boolean): [string, string, string];
|
|
3
|
+
function renameExt(output: string, ext: string, replace?: boolean): string;
|
|
4
|
+
function normalizePath(value: string): string;
|
|
5
|
+
function getWebP_bin(name: string, pathname: string | undefined): string;
|
|
6
|
+
function showInputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
7
|
+
function showOutputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
10
|
export = util;
|