@pi-r/jimp 0.6.7 → 0.7.1
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/README.md +3 -6
- package/index.js +29 -39
- package/package.json +3 -3
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -86,8 +86,7 @@ async function performCommand(host, instance, localUri, command, outputType, fin
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
function execOptions(settings) {
|
|
89
|
-
|
|
90
|
-
const exec = (_a = settings.jimp) === null || _a === void 0 ? void 0 : _a.exec;
|
|
89
|
+
const exec = settings.jimp?.exec;
|
|
91
90
|
let uid, gid;
|
|
92
91
|
if ((0, types_1.isPlainObject)(exec)) {
|
|
93
92
|
let { uid: u, gid: g } = exec;
|
|
@@ -120,8 +119,7 @@ async function transformCommand(localFile, handler, command, outputType, outputA
|
|
|
120
119
|
return handler.rotate();
|
|
121
120
|
default:
|
|
122
121
|
return handler.rotate(localFile, (err, result) => {
|
|
123
|
-
|
|
124
|
-
if (!err && ((_a = handler.host) === null || _a === void 0 ? void 0 : _a.moduleName) === 'filemanager') {
|
|
122
|
+
if (!err && handler.host?.moduleName === 'filemanager') {
|
|
125
123
|
try {
|
|
126
124
|
handler.host.add(result, parent);
|
|
127
125
|
}
|
|
@@ -175,14 +173,13 @@ function getImageCache(tempKey) {
|
|
|
175
173
|
removeFile(tempFile);
|
|
176
174
|
delete stored[tempKey];
|
|
177
175
|
}
|
|
178
|
-
TEMP_DIR
|
|
176
|
+
TEMP_DIR ||= this.getTempDir({ moduleDir: true, increment: 5 });
|
|
179
177
|
return [null, TEMP_DIR ? path.join(TEMP_DIR, (0, types_1.generateUUID)()) : ''];
|
|
180
178
|
}
|
|
181
179
|
function getCacheData() {
|
|
182
|
-
var _a;
|
|
183
180
|
if (!CACHE_INIT) {
|
|
184
181
|
TEMP_DIR = this.getTempDir({ moduleDir: true, increment: 5 });
|
|
185
|
-
const settings =
|
|
182
|
+
const settings = this.settings.jimp ||= {};
|
|
186
183
|
const expires = (0, types_1.parseExpires)(settings.cache_expires || 0);
|
|
187
184
|
if (expires === 0) {
|
|
188
185
|
settings.cache_expires = 0;
|
|
@@ -235,10 +232,12 @@ function getTempPath(ext) {
|
|
|
235
232
|
}
|
|
236
233
|
const removeFile = (pathname) => fs.unlink(pathname, () => { });
|
|
237
234
|
class JimpHandler {
|
|
235
|
+
handler;
|
|
236
|
+
instance;
|
|
237
|
+
_host = null;
|
|
238
238
|
constructor(handler, instance, host) {
|
|
239
239
|
this.handler = handler;
|
|
240
240
|
this.instance = instance;
|
|
241
|
-
this._host = null;
|
|
242
241
|
if (host) {
|
|
243
242
|
this._host = host;
|
|
244
243
|
}
|
|
@@ -266,7 +265,7 @@ class JimpHandler {
|
|
|
266
265
|
const output = leading + value + ext;
|
|
267
266
|
tasks.push(img.writeAsync(output)
|
|
268
267
|
.then(() => this.finalize(output, callback))
|
|
269
|
-
.catch(err => this.instance.writeFail(["Unable to rotate image", "jimp"], err, 2048)));
|
|
268
|
+
.catch((err) => this.instance.writeFail(["Unable to rotate image", "jimp"], err, 2048)));
|
|
270
269
|
}
|
|
271
270
|
}
|
|
272
271
|
if (deg) {
|
|
@@ -387,7 +386,7 @@ class JimpHandler {
|
|
|
387
386
|
const instance = this.instance;
|
|
388
387
|
if (instance.outputAs === 'webp' && path.extname(output).toLowerCase() !== '.webp') {
|
|
389
388
|
const settings = instance.settings;
|
|
390
|
-
const webp = settings.webp
|
|
389
|
+
const webp = settings.webp ||= {};
|
|
391
390
|
const data = instance.qualityData;
|
|
392
391
|
const replace = instance.getCommand().includes('@');
|
|
393
392
|
const filename = (0, util_1.renameExt)(output, 'webp', replace);
|
|
@@ -501,11 +500,10 @@ class JimpHandler {
|
|
|
501
500
|
}
|
|
502
501
|
}
|
|
503
502
|
opacity() {
|
|
504
|
-
var _a;
|
|
505
503
|
if (this.aborted) {
|
|
506
504
|
return;
|
|
507
505
|
}
|
|
508
|
-
const value =
|
|
506
|
+
const value = this.instance.opacityValue ?? NaN;
|
|
509
507
|
if (value >= 0) {
|
|
510
508
|
this.handler = this.handler.opacity(value);
|
|
511
509
|
}
|
|
@@ -544,7 +542,7 @@ class JimpHandler {
|
|
|
544
542
|
}
|
|
545
543
|
return this.handler.writeAsync(output)
|
|
546
544
|
.then(() => this.finalize(output, callback))
|
|
547
|
-
.catch(err => {
|
|
545
|
+
.catch((err) => {
|
|
548
546
|
if (callback) {
|
|
549
547
|
callback(err, '');
|
|
550
548
|
}
|
|
@@ -560,16 +558,10 @@ class JimpHandler {
|
|
|
560
558
|
return this.instance.aborted;
|
|
561
559
|
}
|
|
562
560
|
get rotateCount() {
|
|
563
|
-
|
|
564
|
-
return ((_a = this.instance.rotateData) === null || _a === void 0 ? void 0 : _a.values.length) || 0;
|
|
561
|
+
return this.instance.rotateData?.values.length || 0;
|
|
565
562
|
}
|
|
566
563
|
}
|
|
567
564
|
class Jimp extends Image {
|
|
568
|
-
constructor() {
|
|
569
|
-
super(...arguments);
|
|
570
|
-
this._moduleName = "jimp";
|
|
571
|
-
this._threadable = true;
|
|
572
|
-
}
|
|
573
565
|
static async transform(file, command, options = {}) {
|
|
574
566
|
const [outputType, saveAs, finalAs] = (0, util_1.parseFormat)(command = command.trim(), options.mimeType);
|
|
575
567
|
const empty = () => options.tempFile ? '' : null;
|
|
@@ -635,10 +627,11 @@ class Jimp extends Image {
|
|
|
635
627
|
.catch(() => empty())
|
|
636
628
|
.finally(() => buffer && !options.cache && removeFile(file));
|
|
637
629
|
}
|
|
630
|
+
_moduleName = "jimp";
|
|
631
|
+
_threadable = true;
|
|
638
632
|
parseRotate(value) {
|
|
639
|
-
var _a;
|
|
640
633
|
const data = super.parseRotate(value);
|
|
641
|
-
if (data &&
|
|
634
|
+
if (data && this.settings.jimp?.rotate_clockwise) {
|
|
642
635
|
const values = data.values;
|
|
643
636
|
for (let i = 0; i < values.length; ++i) {
|
|
644
637
|
values[i] *= -1;
|
|
@@ -651,7 +644,6 @@ class Jimp extends Image {
|
|
|
651
644
|
return Promise.reject((0, types_1.createAbortError)());
|
|
652
645
|
}
|
|
653
646
|
return new Promise(async (resolve, reject) => {
|
|
654
|
-
var _a;
|
|
655
647
|
const { host, file } = data;
|
|
656
648
|
const localUri = host.getLocalUri(data);
|
|
657
649
|
const mimeType = host.getMimeType(data);
|
|
@@ -665,7 +657,7 @@ class Jimp extends Image {
|
|
|
665
657
|
}
|
|
666
658
|
const [outputType, saveAs, finalAs] = (0, util_1.parseFormat)(command = command.trim(), mimeType, true);
|
|
667
659
|
if (!outputType) {
|
|
668
|
-
reject((0, types_1.errorValue)("Invalid format",
|
|
660
|
+
reject((0, types_1.errorValue)("Invalid format", /^\w+/.exec(command)?.[0] || "Unknown"));
|
|
669
661
|
return;
|
|
670
662
|
}
|
|
671
663
|
const replace = command.includes('@');
|
|
@@ -746,7 +738,7 @@ class Jimp extends Image {
|
|
|
746
738
|
GifUtil.quantizeSorokin(frame, 256);
|
|
747
739
|
GifUtil.write(output, [frame])
|
|
748
740
|
.then(() => finalize(output))
|
|
749
|
-
.catch(err => errorResponse(err));
|
|
741
|
+
.catch((err) => errorResponse(err));
|
|
750
742
|
}
|
|
751
743
|
catch (err) {
|
|
752
744
|
errorResponse(err);
|
|
@@ -763,7 +755,7 @@ class Jimp extends Image {
|
|
|
763
755
|
});
|
|
764
756
|
}
|
|
765
757
|
})
|
|
766
|
-
.catch(err => {
|
|
758
|
+
.catch((err) => {
|
|
767
759
|
this.writeFail(["Unable to read buffer", path.basename(localUri)], err, { type: 2048, startTime });
|
|
768
760
|
resolve();
|
|
769
761
|
});
|
|
@@ -784,12 +776,11 @@ class Jimp extends Image {
|
|
|
784
776
|
if (outputType === jimp.MIME_GIF || outputType === "image/webp") {
|
|
785
777
|
const cmd = this.parseCommand(command);
|
|
786
778
|
const transformWebP = (target, modified) => {
|
|
787
|
-
var _a;
|
|
788
779
|
if (finalAs === 'webp') {
|
|
789
780
|
if (!modified) {
|
|
790
781
|
startMessage();
|
|
791
782
|
}
|
|
792
|
-
const { path: webp_path, gif2webp } =
|
|
783
|
+
const { path: webp_path, gif2webp } = this.settings.webp ||= {};
|
|
793
784
|
const webp = (0, util_1.renameExt)(output, 'webp', replace);
|
|
794
785
|
const args = [(0, util_1.normalizePath)(target)];
|
|
795
786
|
const quality = cmd.quality;
|
|
@@ -874,11 +865,11 @@ class Jimp extends Image {
|
|
|
874
865
|
}
|
|
875
866
|
GifUtil.write(output, frames, gif)
|
|
876
867
|
.then(() => transformWebP(output, true))
|
|
877
|
-
.catch(err => errorResponse(err));
|
|
868
|
+
.catch((err) => errorResponse(err));
|
|
878
869
|
})
|
|
879
|
-
.catch(err => errorResponse(err));
|
|
870
|
+
.catch((err) => errorResponse(err));
|
|
880
871
|
})
|
|
881
|
-
.catch(err => errorResponse(err));
|
|
872
|
+
.catch((err) => errorResponse(err));
|
|
882
873
|
}
|
|
883
874
|
catch (err) {
|
|
884
875
|
errorResponse(err);
|
|
@@ -895,7 +886,7 @@ class Jimp extends Image {
|
|
|
895
886
|
else if (mimeType === "image/webp") {
|
|
896
887
|
const tryWebpMux = async () => {
|
|
897
888
|
try {
|
|
898
|
-
const webp = new (WEBPMUX
|
|
889
|
+
const webp = new (WEBPMUX ||= require('node-webpmux')).Image();
|
|
899
890
|
if (!WEBPMUX_INIT) {
|
|
900
891
|
await webp.initLib();
|
|
901
892
|
WEBPMUX_INIT = true;
|
|
@@ -927,7 +918,7 @@ class Jimp extends Image {
|
|
|
927
918
|
}
|
|
928
919
|
GifUtil.write(output, frames, { loops: webp.anim.loops })
|
|
929
920
|
.then(() => finalize(output))
|
|
930
|
-
.catch(err => errorResponse(err));
|
|
921
|
+
.catch((err) => errorResponse(err));
|
|
931
922
|
}
|
|
932
923
|
catch (err) {
|
|
933
924
|
errorResponse(err);
|
|
@@ -950,12 +941,12 @@ class Jimp extends Image {
|
|
|
950
941
|
.then(() => {
|
|
951
942
|
webp.save(output, { width: w, height: h, bgColor: cmd.rotate ? [0, 0, 0, 0] : undefined })
|
|
952
943
|
.then(() => finalize(output))
|
|
953
|
-
.catch(err => errorResponse(err));
|
|
944
|
+
.catch((err) => errorResponse(err));
|
|
954
945
|
})
|
|
955
|
-
.catch(err => errorResponse(err));
|
|
946
|
+
.catch((err) => errorResponse(err));
|
|
956
947
|
}
|
|
957
948
|
})
|
|
958
|
-
.catch(err => errorResponse(err));
|
|
949
|
+
.catch((err) => errorResponse(err));
|
|
959
950
|
}
|
|
960
951
|
else {
|
|
961
952
|
resolve();
|
|
@@ -974,7 +965,7 @@ class Jimp extends Image {
|
|
|
974
965
|
return false;
|
|
975
966
|
};
|
|
976
967
|
const settings = this.settings;
|
|
977
|
-
const { path: webp_path } = settings.webp
|
|
968
|
+
const { path: webp_path } = settings.webp ||= {};
|
|
978
969
|
const bmpFile = getTempPath.call(this, 'bmp');
|
|
979
970
|
try {
|
|
980
971
|
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, ...execOptions(settings) }, err => {
|
|
@@ -1004,8 +995,7 @@ class Jimp extends Image {
|
|
|
1004
995
|
});
|
|
1005
996
|
}
|
|
1006
997
|
get settings() {
|
|
1007
|
-
|
|
1008
|
-
return (_a = this.module).settings || (_a.settings = {});
|
|
998
|
+
return this.module.settings ||= {};
|
|
1009
999
|
}
|
|
1010
1000
|
}
|
|
1011
1001
|
module.exports = Jimp;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/jimp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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.
|
|
24
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/image": "^0.9.2",
|
|
24
|
+
"@e-mc/types": "^0.9.2",
|
|
25
25
|
"bmp-js": "^0.1.0",
|
|
26
26
|
"gifwrap": "^0.10.1",
|
|
27
27
|
"jimp": "^0.22.12"
|