@pi-r/jimp 0.6.5 → 0.7.0
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 +23 -28
- package/package.json +3 -3
- package/util.js +0 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -173,14 +173,13 @@ function getImageCache(tempKey) {
|
|
|
173
173
|
removeFile(tempFile);
|
|
174
174
|
delete stored[tempKey];
|
|
175
175
|
}
|
|
176
|
-
TEMP_DIR
|
|
176
|
+
TEMP_DIR ||= this.getTempDir({ moduleDir: true, increment: 5 });
|
|
177
177
|
return [null, TEMP_DIR ? path.join(TEMP_DIR, (0, types_1.generateUUID)()) : ''];
|
|
178
178
|
}
|
|
179
179
|
function getCacheData() {
|
|
180
|
-
var _a;
|
|
181
180
|
if (!CACHE_INIT) {
|
|
182
181
|
TEMP_DIR = this.getTempDir({ moduleDir: true, increment: 5 });
|
|
183
|
-
const settings =
|
|
182
|
+
const settings = this.settings.jimp ||= {};
|
|
184
183
|
const expires = (0, types_1.parseExpires)(settings.cache_expires || 0);
|
|
185
184
|
if (expires === 0) {
|
|
186
185
|
settings.cache_expires = 0;
|
|
@@ -233,10 +232,12 @@ function getTempPath(ext) {
|
|
|
233
232
|
}
|
|
234
233
|
const removeFile = (pathname) => fs.unlink(pathname, () => { });
|
|
235
234
|
class JimpHandler {
|
|
235
|
+
handler;
|
|
236
|
+
instance;
|
|
237
|
+
_host = null;
|
|
236
238
|
constructor(handler, instance, host) {
|
|
237
239
|
this.handler = handler;
|
|
238
240
|
this.instance = instance;
|
|
239
|
-
this._host = null;
|
|
240
241
|
if (host) {
|
|
241
242
|
this._host = host;
|
|
242
243
|
}
|
|
@@ -264,7 +265,7 @@ class JimpHandler {
|
|
|
264
265
|
const output = leading + value + ext;
|
|
265
266
|
tasks.push(img.writeAsync(output)
|
|
266
267
|
.then(() => this.finalize(output, callback))
|
|
267
|
-
.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)));
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
271
|
if (deg) {
|
|
@@ -385,7 +386,7 @@ class JimpHandler {
|
|
|
385
386
|
const instance = this.instance;
|
|
386
387
|
if (instance.outputAs === 'webp' && path.extname(output).toLowerCase() !== '.webp') {
|
|
387
388
|
const settings = instance.settings;
|
|
388
|
-
const webp = settings.webp
|
|
389
|
+
const webp = settings.webp ||= {};
|
|
389
390
|
const data = instance.qualityData;
|
|
390
391
|
const replace = instance.getCommand().includes('@');
|
|
391
392
|
const filename = (0, util_1.renameExt)(output, 'webp', replace);
|
|
@@ -541,7 +542,7 @@ class JimpHandler {
|
|
|
541
542
|
}
|
|
542
543
|
return this.handler.writeAsync(output)
|
|
543
544
|
.then(() => this.finalize(output, callback))
|
|
544
|
-
.catch(err => {
|
|
545
|
+
.catch((err) => {
|
|
545
546
|
if (callback) {
|
|
546
547
|
callback(err, '');
|
|
547
548
|
}
|
|
@@ -561,11 +562,6 @@ class JimpHandler {
|
|
|
561
562
|
}
|
|
562
563
|
}
|
|
563
564
|
class Jimp extends Image {
|
|
564
|
-
constructor() {
|
|
565
|
-
super(...arguments);
|
|
566
|
-
this._moduleName = "jimp";
|
|
567
|
-
this._threadable = true;
|
|
568
|
-
}
|
|
569
565
|
static async transform(file, command, options = {}) {
|
|
570
566
|
const [outputType, saveAs, finalAs] = (0, util_1.parseFormat)(command = command.trim(), options.mimeType);
|
|
571
567
|
const empty = () => options.tempFile ? '' : null;
|
|
@@ -631,6 +627,8 @@ class Jimp extends Image {
|
|
|
631
627
|
.catch(() => empty())
|
|
632
628
|
.finally(() => buffer && !options.cache && removeFile(file));
|
|
633
629
|
}
|
|
630
|
+
_moduleName = "jimp";
|
|
631
|
+
_threadable = true;
|
|
634
632
|
parseRotate(value) {
|
|
635
633
|
const data = super.parseRotate(value);
|
|
636
634
|
if (data && this.settings.jimp?.rotate_clockwise) {
|
|
@@ -740,7 +738,7 @@ class Jimp extends Image {
|
|
|
740
738
|
GifUtil.quantizeSorokin(frame, 256);
|
|
741
739
|
GifUtil.write(output, [frame])
|
|
742
740
|
.then(() => finalize(output))
|
|
743
|
-
.catch(err => errorResponse(err));
|
|
741
|
+
.catch((err) => errorResponse(err));
|
|
744
742
|
}
|
|
745
743
|
catch (err) {
|
|
746
744
|
errorResponse(err);
|
|
@@ -757,7 +755,7 @@ class Jimp extends Image {
|
|
|
757
755
|
});
|
|
758
756
|
}
|
|
759
757
|
})
|
|
760
|
-
.catch(err => {
|
|
758
|
+
.catch((err) => {
|
|
761
759
|
this.writeFail(["Unable to read buffer", path.basename(localUri)], err, { type: 2048, startTime });
|
|
762
760
|
resolve();
|
|
763
761
|
});
|
|
@@ -778,12 +776,11 @@ class Jimp extends Image {
|
|
|
778
776
|
if (outputType === jimp.MIME_GIF || outputType === "image/webp") {
|
|
779
777
|
const cmd = this.parseCommand(command);
|
|
780
778
|
const transformWebP = (target, modified) => {
|
|
781
|
-
var _a;
|
|
782
779
|
if (finalAs === 'webp') {
|
|
783
780
|
if (!modified) {
|
|
784
781
|
startMessage();
|
|
785
782
|
}
|
|
786
|
-
const { path: webp_path, gif2webp } =
|
|
783
|
+
const { path: webp_path, gif2webp } = this.settings.webp ||= {};
|
|
787
784
|
const webp = (0, util_1.renameExt)(output, 'webp', replace);
|
|
788
785
|
const args = [(0, util_1.normalizePath)(target)];
|
|
789
786
|
const quality = cmd.quality;
|
|
@@ -868,11 +865,11 @@ class Jimp extends Image {
|
|
|
868
865
|
}
|
|
869
866
|
GifUtil.write(output, frames, gif)
|
|
870
867
|
.then(() => transformWebP(output, true))
|
|
871
|
-
.catch(err => errorResponse(err));
|
|
868
|
+
.catch((err) => errorResponse(err));
|
|
872
869
|
})
|
|
873
|
-
.catch(err => errorResponse(err));
|
|
870
|
+
.catch((err) => errorResponse(err));
|
|
874
871
|
})
|
|
875
|
-
.catch(err => errorResponse(err));
|
|
872
|
+
.catch((err) => errorResponse(err));
|
|
876
873
|
}
|
|
877
874
|
catch (err) {
|
|
878
875
|
errorResponse(err);
|
|
@@ -889,7 +886,7 @@ class Jimp extends Image {
|
|
|
889
886
|
else if (mimeType === "image/webp") {
|
|
890
887
|
const tryWebpMux = async () => {
|
|
891
888
|
try {
|
|
892
|
-
const webp = new (WEBPMUX
|
|
889
|
+
const webp = new (WEBPMUX ||= require('node-webpmux')).Image();
|
|
893
890
|
if (!WEBPMUX_INIT) {
|
|
894
891
|
await webp.initLib();
|
|
895
892
|
WEBPMUX_INIT = true;
|
|
@@ -921,7 +918,7 @@ class Jimp extends Image {
|
|
|
921
918
|
}
|
|
922
919
|
GifUtil.write(output, frames, { loops: webp.anim.loops })
|
|
923
920
|
.then(() => finalize(output))
|
|
924
|
-
.catch(err => errorResponse(err));
|
|
921
|
+
.catch((err) => errorResponse(err));
|
|
925
922
|
}
|
|
926
923
|
catch (err) {
|
|
927
924
|
errorResponse(err);
|
|
@@ -944,12 +941,12 @@ class Jimp extends Image {
|
|
|
944
941
|
.then(() => {
|
|
945
942
|
webp.save(output, { width: w, height: h, bgColor: cmd.rotate ? [0, 0, 0, 0] : undefined })
|
|
946
943
|
.then(() => finalize(output))
|
|
947
|
-
.catch(err => errorResponse(err));
|
|
944
|
+
.catch((err) => errorResponse(err));
|
|
948
945
|
})
|
|
949
|
-
.catch(err => errorResponse(err));
|
|
946
|
+
.catch((err) => errorResponse(err));
|
|
950
947
|
}
|
|
951
948
|
})
|
|
952
|
-
.catch(err => errorResponse(err));
|
|
949
|
+
.catch((err) => errorResponse(err));
|
|
953
950
|
}
|
|
954
951
|
else {
|
|
955
952
|
resolve();
|
|
@@ -968,7 +965,7 @@ class Jimp extends Image {
|
|
|
968
965
|
return false;
|
|
969
966
|
};
|
|
970
967
|
const settings = this.settings;
|
|
971
|
-
const { path: webp_path } = settings.webp
|
|
968
|
+
const { path: webp_path } = settings.webp ||= {};
|
|
972
969
|
const bmpFile = getTempPath.call(this, 'bmp');
|
|
973
970
|
try {
|
|
974
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 => {
|
|
@@ -998,9 +995,7 @@ class Jimp extends Image {
|
|
|
998
995
|
});
|
|
999
996
|
}
|
|
1000
997
|
get settings() {
|
|
1001
|
-
|
|
1002
|
-
return (_a = this.module).settings || (_a.settings = {});
|
|
998
|
+
return this.module.settings ||= {};
|
|
1003
999
|
}
|
|
1004
1000
|
}
|
|
1005
|
-
|
|
1006
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.0",
|
|
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.0",
|
|
24
|
+
"@e-mc/types": "^0.9.0",
|
|
25
25
|
"bmp-js": "^0.1.0",
|
|
26
26
|
"gifwrap": "^0.10.1",
|
|
27
27
|
"jimp": "^0.22.12"
|
package/util.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
exports.showOutputType = exports.showInputType = exports.getWebP_bin = exports.normalizePath = exports.renameExt = exports.parseFormat = exports.MIME_OUTPUT = exports.MIME_INPUT = void 0;
|
|
4
3
|
const path = require("path");
|
|
5
4
|
const fs = require("fs");
|