@pi-r/jimp 0.9.2 → 0.9.4
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/index.d.ts +7 -0
- package/index.js +29 -33
- package/package.json +4 -3
- package/util.d.ts +2 -0
- package/util.js +10 -5
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -273,7 +273,7 @@ class JimpHandler {
|
|
|
273
273
|
const output = leading + value + ext;
|
|
274
274
|
tasks.push(img.writeAsync(output)
|
|
275
275
|
.then(() => {
|
|
276
|
-
this.finalize(output, callback);
|
|
276
|
+
void this.finalize(output, callback);
|
|
277
277
|
})
|
|
278
278
|
.catch((err) => {
|
|
279
279
|
this.instance.writeFail(["Unable to rotate image", "jimp"], err, 2048);
|
|
@@ -391,7 +391,7 @@ class JimpHandler {
|
|
|
391
391
|
}
|
|
392
392
|
this.handler.background(value);
|
|
393
393
|
}
|
|
394
|
-
finalize(output, callback) {
|
|
394
|
+
async finalize(output, callback) {
|
|
395
395
|
if (this.aborted) {
|
|
396
396
|
return;
|
|
397
397
|
}
|
|
@@ -445,7 +445,7 @@ class JimpHandler {
|
|
|
445
445
|
}
|
|
446
446
|
args.push('-o', (0, util_1.normalizePath)(filename));
|
|
447
447
|
try {
|
|
448
|
-
child_process.execFile((0, util_1.
|
|
448
|
+
child_process.execFile(await (0, util_1.importBinary)('cwebp', webp.path), args, { shell: true, signal: this.instance.signal, ...execOptions(settings) }, err => {
|
|
449
449
|
if (err) {
|
|
450
450
|
this.instance.writeFail(["Unable to convert file", path.basename(filename)], err, 2048);
|
|
451
451
|
}
|
|
@@ -466,7 +466,7 @@ class JimpHandler {
|
|
|
466
466
|
});
|
|
467
467
|
}
|
|
468
468
|
catch (err) {
|
|
469
|
-
this.instance.checkPackage(err, 'cwebp-bin
|
|
469
|
+
this.instance.checkPackage(err, 'cwebp-bin', "Unknown", { type: 2048, passThrough: !!callback });
|
|
470
470
|
if (callback) {
|
|
471
471
|
callback(err, '');
|
|
472
472
|
}
|
|
@@ -488,7 +488,7 @@ class JimpHandler {
|
|
|
488
488
|
resolve(emptyData());
|
|
489
489
|
return;
|
|
490
490
|
}
|
|
491
|
-
this.finalize(output, (error, result) => {
|
|
491
|
+
void this.finalize(output, (error, result) => {
|
|
492
492
|
if (error) {
|
|
493
493
|
resolve(emptyData());
|
|
494
494
|
}
|
|
@@ -551,7 +551,7 @@ class JimpHandler {
|
|
|
551
551
|
}
|
|
552
552
|
this.handler.write(output, err => {
|
|
553
553
|
if (!err) {
|
|
554
|
-
this.finalize(output, callback);
|
|
554
|
+
void this.finalize(output, callback);
|
|
555
555
|
}
|
|
556
556
|
else if (callback) {
|
|
557
557
|
callback(err, '');
|
|
@@ -567,7 +567,7 @@ class JimpHandler {
|
|
|
567
567
|
}
|
|
568
568
|
return this.handler.writeAsync(output)
|
|
569
569
|
.then(() => {
|
|
570
|
-
this.finalize(output, callback);
|
|
570
|
+
void this.finalize(output, callback);
|
|
571
571
|
})
|
|
572
572
|
.catch((err) => {
|
|
573
573
|
if (callback) {
|
|
@@ -760,7 +760,7 @@ class Jimp extends Image {
|
|
|
760
760
|
};
|
|
761
761
|
const transformBuffer = (bmpFile) => {
|
|
762
762
|
startMessage();
|
|
763
|
-
performCommand(host, this, localUri, command,
|
|
763
|
+
performCommand(host, this, localUri, command, outputType, outputAs, bmpFile || file.buffer, file)
|
|
764
764
|
.then((img) => {
|
|
765
765
|
if (typeof bmpFile === 'string') {
|
|
766
766
|
removeFile(bmpFile);
|
|
@@ -800,17 +800,13 @@ class Jimp extends Image {
|
|
|
800
800
|
resolve();
|
|
801
801
|
});
|
|
802
802
|
};
|
|
803
|
-
const errorResponse = (err) => {
|
|
804
|
-
this.writeFail(["Unable to convert file", path.basename(localUri)], err, { type: 2048, startTime });
|
|
805
|
-
resolve();
|
|
806
|
-
};
|
|
807
803
|
const startMessage = () => {
|
|
808
804
|
host.formatMessage(2048, "jimp", ["Transforming image...", path.basename(localUri)], command);
|
|
809
805
|
};
|
|
810
806
|
if (mimeType === jimp.MIME_GIF) {
|
|
811
807
|
if (outputType === jimp.MIME_GIF || outputType === "image/webp") {
|
|
812
808
|
const cmd = this.parseCommand(command);
|
|
813
|
-
const transformWebP = (target, modified) => {
|
|
809
|
+
const transformWebP = async (target, modified) => {
|
|
814
810
|
if (outputAs === 'webp') {
|
|
815
811
|
if (!modified) {
|
|
816
812
|
startMessage();
|
|
@@ -854,22 +850,22 @@ class Jimp extends Image {
|
|
|
854
850
|
}
|
|
855
851
|
args.push('-o', (0, util_1.normalizePath)(webp));
|
|
856
852
|
try {
|
|
857
|
-
child_process.execFile((0, util_1.
|
|
853
|
+
child_process.execFile(await (0, util_1.importBinary)('gif2webp', webp_path), args, { shell: true, signal: this.signal, ...execOptions(this.settings) }, (err, stdout) => {
|
|
858
854
|
if (!err) {
|
|
859
855
|
this.addLog(types_1.STATUS_TYPE.INFO, stdout);
|
|
860
856
|
finalize(webp);
|
|
861
857
|
}
|
|
862
858
|
else {
|
|
863
|
-
|
|
859
|
+
reject(err);
|
|
864
860
|
}
|
|
865
861
|
});
|
|
866
862
|
}
|
|
867
863
|
catch (err) {
|
|
868
|
-
if (this.checkPackage(err, 'gif2webp-bin
|
|
864
|
+
if (this.checkPackage(err, 'gif2webp-bin', 2048)) {
|
|
869
865
|
resolve();
|
|
870
866
|
}
|
|
871
867
|
else {
|
|
872
|
-
|
|
868
|
+
reject(err);
|
|
873
869
|
}
|
|
874
870
|
}
|
|
875
871
|
}
|
|
@@ -913,20 +909,20 @@ class Jimp extends Image {
|
|
|
913
909
|
}
|
|
914
910
|
GifUtil.write(output, frames, gif)
|
|
915
911
|
.then(() => {
|
|
916
|
-
transformWebP(output, true);
|
|
912
|
+
void transformWebP(output, true);
|
|
917
913
|
})
|
|
918
|
-
.catch(
|
|
914
|
+
.catch(reject);
|
|
919
915
|
})
|
|
920
|
-
.catch(
|
|
916
|
+
.catch(reject);
|
|
921
917
|
})
|
|
922
|
-
.catch(
|
|
918
|
+
.catch(reject);
|
|
923
919
|
}
|
|
924
920
|
catch (err) {
|
|
925
|
-
|
|
921
|
+
reject(err);
|
|
926
922
|
}
|
|
927
923
|
}
|
|
928
924
|
else {
|
|
929
|
-
transformWebP(localUri, false);
|
|
925
|
+
void transformWebP(localUri, false);
|
|
930
926
|
}
|
|
931
927
|
}
|
|
932
928
|
else {
|
|
@@ -983,10 +979,10 @@ class Jimp extends Image {
|
|
|
983
979
|
.then(() => {
|
|
984
980
|
finalize(output);
|
|
985
981
|
})
|
|
986
|
-
.catch(
|
|
982
|
+
.catch(reject);
|
|
987
983
|
}
|
|
988
984
|
catch (err) {
|
|
989
|
-
|
|
985
|
+
reject(err);
|
|
990
986
|
}
|
|
991
987
|
}
|
|
992
988
|
else {
|
|
@@ -1008,12 +1004,12 @@ class Jimp extends Image {
|
|
|
1008
1004
|
.then(() => {
|
|
1009
1005
|
finalize(output);
|
|
1010
1006
|
})
|
|
1011
|
-
.catch(
|
|
1007
|
+
.catch(reject);
|
|
1012
1008
|
})
|
|
1013
|
-
.catch(
|
|
1009
|
+
.catch(reject);
|
|
1014
1010
|
}
|
|
1015
1011
|
})
|
|
1016
|
-
.catch(
|
|
1012
|
+
.catch(reject);
|
|
1017
1013
|
}
|
|
1018
1014
|
else {
|
|
1019
1015
|
resolve();
|
|
@@ -1024,7 +1020,7 @@ class Jimp extends Image {
|
|
|
1024
1020
|
if (WEBPMUX_INIT) {
|
|
1025
1021
|
this.writeFail(["Unknown", 'node-webpmux'], err, { type: 2048, startTime });
|
|
1026
1022
|
}
|
|
1027
|
-
else if (this.checkPackage(err, 'node-webpmux
|
|
1023
|
+
else if (this.checkPackage(err, 'node-webpmux', 2048)) {
|
|
1028
1024
|
resolve();
|
|
1029
1025
|
return true;
|
|
1030
1026
|
}
|
|
@@ -1035,7 +1031,7 @@ class Jimp extends Image {
|
|
|
1035
1031
|
const { path: webp_path } = settings.webp ||= {};
|
|
1036
1032
|
const bmpFile = getTempPath(this, 'bmp');
|
|
1037
1033
|
try {
|
|
1038
|
-
child_process.execFile((0, util_1.
|
|
1034
|
+
child_process.execFile(await (0, util_1.importBinary)('dwebp', webp_path), [(0, util_1.normalizePath)(localUri), '-bmp', '-o', (0, util_1.normalizePath)(bmpFile)], { shell: true, signal: this.signal, ...execOptions(settings) }, err => {
|
|
1039
1035
|
if (!err) {
|
|
1040
1036
|
transformBuffer(bmpFile);
|
|
1041
1037
|
}
|
|
@@ -1043,7 +1039,7 @@ class Jimp extends Image {
|
|
|
1043
1039
|
removeFile(bmpFile);
|
|
1044
1040
|
void tryWebpMux().then(valid => {
|
|
1045
1041
|
if (!valid) {
|
|
1046
|
-
|
|
1042
|
+
reject(err);
|
|
1047
1043
|
}
|
|
1048
1044
|
});
|
|
1049
1045
|
}
|
|
@@ -1051,11 +1047,11 @@ class Jimp extends Image {
|
|
|
1051
1047
|
}
|
|
1052
1048
|
catch (err) {
|
|
1053
1049
|
if (!await tryWebpMux()) {
|
|
1054
|
-
if (this.checkPackage(err, 'dwebp-bin
|
|
1050
|
+
if (this.checkPackage(err, 'dwebp-bin', 2048)) {
|
|
1055
1051
|
resolve();
|
|
1056
1052
|
}
|
|
1057
1053
|
else {
|
|
1058
|
-
|
|
1054
|
+
reject(err);
|
|
1059
1055
|
}
|
|
1060
1056
|
}
|
|
1061
1057
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/jimp",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "Jimp V0 image constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
8
9
|
},
|
|
@@ -19,8 +20,8 @@
|
|
|
19
20
|
"license": "MIT",
|
|
20
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@e-mc/image": "^0.11.
|
|
23
|
-
"@e-mc/types": "^0.11.
|
|
23
|
+
"@e-mc/image": "^0.11.5",
|
|
24
|
+
"@e-mc/types": "^0.11.5",
|
|
24
25
|
"bmp-js": "^0.1.0",
|
|
25
26
|
"gifwrap": "^0.10.1",
|
|
26
27
|
"jimp": "^0.22.12"
|
package/util.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ declare namespace util {
|
|
|
2
2
|
function parseFormat(command: string, mimeType?: string, gif?: boolean): [string, string, string];
|
|
3
3
|
function renameExt(output: string, ext: string, replace?: boolean): string;
|
|
4
4
|
function normalizePath(value: string): string;
|
|
5
|
+
/** @deprecated */
|
|
5
6
|
function getWebP_bin(name: string, pathname: string | undefined): string;
|
|
7
|
+
function importBinary(name: string, pathname: string | undefined): Promise<string>;
|
|
6
8
|
function showInputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
7
9
|
function showOutputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
8
10
|
}
|
package/util.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.parseFormat = parseFormat;
|
|
|
4
4
|
exports.renameExt = renameExt;
|
|
5
5
|
exports.normalizePath = normalizePath;
|
|
6
6
|
exports.getWebP_bin = getWebP_bin;
|
|
7
|
+
exports.importBinary = importBinary;
|
|
7
8
|
exports.showInputType = showInputType;
|
|
8
9
|
exports.showOutputType = showOutputType;
|
|
9
10
|
const path = require("node:path");
|
|
@@ -46,14 +47,10 @@ function parseFormat(command, mimeType, gif) {
|
|
|
46
47
|
mime = jimp.MIME_GIF;
|
|
47
48
|
saveAs = 'gif';
|
|
48
49
|
}
|
|
49
|
-
else
|
|
50
|
+
else {
|
|
50
51
|
mime = jimp.MIME_PNG;
|
|
51
52
|
saveAs = 'png';
|
|
52
53
|
}
|
|
53
|
-
else {
|
|
54
|
-
mime = jimp.MIME_BMP;
|
|
55
|
-
saveAs = 'bmp';
|
|
56
|
-
}
|
|
57
54
|
outputAs = 'webp';
|
|
58
55
|
break;
|
|
59
56
|
}
|
|
@@ -88,6 +85,14 @@ function getWebP_bin(name, pathname) {
|
|
|
88
85
|
}
|
|
89
86
|
return require(name + '-bin');
|
|
90
87
|
}
|
|
88
|
+
async function importBinary(name, pathname) {
|
|
89
|
+
if (pathname && fs.existsSync(pathname)) {
|
|
90
|
+
name += Image.PLATFORM_WIN32 ? '.exe' : '';
|
|
91
|
+
const bin = path.join(pathname, name);
|
|
92
|
+
return Image.sanitizeCmd(fs.existsSync(bin) ? bin : path.join(pathname, 'bin', name));
|
|
93
|
+
}
|
|
94
|
+
return types.importESM(name + '-bin', true);
|
|
95
|
+
}
|
|
91
96
|
function showInputType(value, outputType, outputAs) {
|
|
92
97
|
if (outputAs) {
|
|
93
98
|
outputType = 'image/' + outputAs;
|