@pi-r/jimp 0.8.0 → 0.8.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/index.js +54 -45
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
package/index.js
CHANGED
|
@@ -118,17 +118,16 @@ async function transformCommand(localFile, handler, command, outputType, outputA
|
|
|
118
118
|
return handler;
|
|
119
119
|
case 1:
|
|
120
120
|
return handler.rotate();
|
|
121
|
-
default:
|
|
122
|
-
return handler.rotate(localFile, (err, result) => {
|
|
123
|
-
if (!err && handler.host?.moduleName === 'filemanager') {
|
|
124
|
-
try {
|
|
125
|
-
handler.host.add(result, parent);
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
121
|
}
|
|
122
|
+
return handler.rotate(localFile, (err, result) => {
|
|
123
|
+
if (!err && handler.host?.moduleName === 'filemanager') {
|
|
124
|
+
try {
|
|
125
|
+
handler.host.add(result, parent);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
132
131
|
}
|
|
133
132
|
function setImageCache(instance, tempKey, tempFile, output, localFile) {
|
|
134
133
|
try {
|
|
@@ -190,10 +189,10 @@ function getCacheData(instance) {
|
|
|
190
189
|
Image.removeDir(TEMP_DIR, true);
|
|
191
190
|
}
|
|
192
191
|
else {
|
|
193
|
-
const current = Date.now();
|
|
194
192
|
try {
|
|
193
|
+
const current = Date.now();
|
|
195
194
|
fs.readdirSync(TEMP_DIR, { withFileTypes: true }).forEach(item => {
|
|
196
|
-
if (item.isFile() && item.name
|
|
195
|
+
if (item.isFile() && path.extname(item.name) === '.json') {
|
|
197
196
|
const pathname = path.join(TEMP_DIR, item.name);
|
|
198
197
|
try {
|
|
199
198
|
const data = JSON.parse(fs.readFileSync(pathname, 'utf-8'));
|
|
@@ -231,9 +230,16 @@ function getTempPath(instance, ext) {
|
|
|
231
230
|
const tempDir = TEMP_DIR || instance.getTempDir({ moduleDir: true, createDir: true }) || instance.getTempDir();
|
|
232
231
|
return path.join(tempDir, (0, crypto_1.randomUUID)() + '.' + ext);
|
|
233
232
|
}
|
|
233
|
+
function rotateAnim(cmd) {
|
|
234
|
+
const rotate = cmd.rotate;
|
|
235
|
+
if (rotate) {
|
|
236
|
+
rotate.values = [rotate.values.pop()];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
234
239
|
function removeFile(pathname) {
|
|
235
240
|
fs.unlink(pathname, () => { });
|
|
236
241
|
}
|
|
242
|
+
const hasTransform = (cmd) => !!(cmd.rotate || cmd.opacity >= 0 && cmd.opacity < 1 || cmd.resize || cmd.crop || cmd.method);
|
|
237
243
|
const emptyResult = (options) => (options.tempFile ? '' : null);
|
|
238
244
|
class JimpHandler {
|
|
239
245
|
handler;
|
|
@@ -765,9 +771,7 @@ class Jimp extends Image {
|
|
|
765
771
|
.then(() => {
|
|
766
772
|
finalize(output);
|
|
767
773
|
})
|
|
768
|
-
.catch(
|
|
769
|
-
errorResponse(err);
|
|
770
|
-
});
|
|
774
|
+
.catch(errorResponse);
|
|
771
775
|
}
|
|
772
776
|
catch (err) {
|
|
773
777
|
errorResponse(err);
|
|
@@ -793,13 +797,6 @@ class Jimp extends Image {
|
|
|
793
797
|
this.writeFail(["Unable to convert file", path.basename(localUri)], err, { type: 2048, startTime });
|
|
794
798
|
resolve();
|
|
795
799
|
};
|
|
796
|
-
const rotateAnim = (cmd) => {
|
|
797
|
-
const rotate = cmd.rotate;
|
|
798
|
-
if (rotate) {
|
|
799
|
-
rotate.values = [rotate.values.pop()];
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
const hasTransform = (cmd) => !!(cmd.rotate || cmd.opacity >= 0 && cmd.opacity < 1 || cmd.resize || cmd.crop || cmd.method);
|
|
803
800
|
const startMessage = () => {
|
|
804
801
|
host.formatMessage(2048, "jimp", ["Transforming image...", path.basename(localUri)], command);
|
|
805
802
|
};
|
|
@@ -888,27 +885,34 @@ class Jimp extends Image {
|
|
|
888
885
|
return transformCommand(localUri, handler, cmd, jimp.MIME_GIF);
|
|
889
886
|
}))
|
|
890
887
|
.then(items => {
|
|
888
|
+
const quantize = this.settings.jimp?.gifwrap_quantize || '';
|
|
891
889
|
const frames = gif.frames;
|
|
892
890
|
for (let i = 0, length = items.length; i < length; ++i) {
|
|
893
891
|
const img = new BitmapImage(items[i].handler.bitmap);
|
|
894
|
-
|
|
892
|
+
switch (quantize) {
|
|
893
|
+
case 'none':
|
|
894
|
+
break;
|
|
895
|
+
case 'dekker':
|
|
896
|
+
GifUtil.quantizeDekker(img, 256);
|
|
897
|
+
break;
|
|
898
|
+
case 'wu':
|
|
899
|
+
GifUtil.quantizeWu(img, 256);
|
|
900
|
+
break;
|
|
901
|
+
default:
|
|
902
|
+
GifUtil.quantizeSorokin(img, 256);
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
895
905
|
frames[i].bitmap = img.bitmap;
|
|
896
906
|
}
|
|
897
907
|
GifUtil.write(output, frames, gif)
|
|
898
908
|
.then(() => {
|
|
899
909
|
transformWebP(output, true);
|
|
900
910
|
})
|
|
901
|
-
.catch(
|
|
902
|
-
errorResponse(err);
|
|
903
|
-
});
|
|
911
|
+
.catch(errorResponse);
|
|
904
912
|
})
|
|
905
|
-
.catch(
|
|
906
|
-
errorResponse(err);
|
|
907
|
-
});
|
|
913
|
+
.catch(errorResponse);
|
|
908
914
|
})
|
|
909
|
-
.catch(
|
|
910
|
-
errorResponse(err);
|
|
911
|
-
});
|
|
915
|
+
.catch(errorResponse);
|
|
912
916
|
}
|
|
913
917
|
catch (err) {
|
|
914
918
|
errorResponse(err);
|
|
@@ -948,20 +952,31 @@ class Jimp extends Image {
|
|
|
948
952
|
if (outputType === jimp.MIME_GIF) {
|
|
949
953
|
try {
|
|
950
954
|
const { GifFrame, GifUtil, BitmapImage } = gifwrap;
|
|
955
|
+
const quantize = this.settings.jimp?.gifwrap_quantize || '';
|
|
951
956
|
const frames = new Array(length);
|
|
952
957
|
for (let i = 0; i < length; ++i) {
|
|
953
958
|
const { x, y, delay } = webp.frames[i];
|
|
954
959
|
const img = new BitmapImage(items[i].handler.bitmap);
|
|
955
|
-
|
|
960
|
+
switch (quantize) {
|
|
961
|
+
case 'none':
|
|
962
|
+
break;
|
|
963
|
+
case 'dekker':
|
|
964
|
+
GifUtil.quantizeDekker(img, 256);
|
|
965
|
+
break;
|
|
966
|
+
case 'wu':
|
|
967
|
+
GifUtil.quantizeWu(img, 256);
|
|
968
|
+
break;
|
|
969
|
+
default:
|
|
970
|
+
GifUtil.quantizeSorokin(img, 256);
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
956
973
|
frames[i] = new GifFrame(new BitmapImage(img), { xOffset: x, yOffset: y, delayCentisecs: delay / 10 });
|
|
957
974
|
}
|
|
958
975
|
GifUtil.write(output, frames, { loops: webp.anim.loops })
|
|
959
976
|
.then(() => {
|
|
960
977
|
finalize(output);
|
|
961
978
|
})
|
|
962
|
-
.catch(
|
|
963
|
-
errorResponse(err);
|
|
964
|
-
});
|
|
979
|
+
.catch(errorResponse);
|
|
965
980
|
}
|
|
966
981
|
catch (err) {
|
|
967
982
|
errorResponse(err);
|
|
@@ -986,18 +1001,12 @@ class Jimp extends Image {
|
|
|
986
1001
|
.then(() => {
|
|
987
1002
|
finalize(output);
|
|
988
1003
|
})
|
|
989
|
-
.catch(
|
|
990
|
-
errorResponse(err);
|
|
991
|
-
});
|
|
1004
|
+
.catch(errorResponse);
|
|
992
1005
|
})
|
|
993
|
-
.catch(
|
|
994
|
-
errorResponse(err);
|
|
995
|
-
});
|
|
1006
|
+
.catch(errorResponse);
|
|
996
1007
|
}
|
|
997
1008
|
})
|
|
998
|
-
.catch(
|
|
999
|
-
errorResponse(err);
|
|
1000
|
-
});
|
|
1009
|
+
.catch(errorResponse);
|
|
1001
1010
|
}
|
|
1002
1011
|
else {
|
|
1003
1012
|
resolve();
|
package/package.json
CHANGED