@pi-r/jimp 0.3.0 → 0.5.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/index.js +92 -82
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -24,13 +24,16 @@ const METHOD_ALIAS = {
|
|
|
24
24
|
composite: 'cp',
|
|
25
25
|
mask: 'ma',
|
|
26
26
|
convolute: 'cl',
|
|
27
|
+
convolution: 'cl',
|
|
27
28
|
flip: 'fl',
|
|
28
29
|
mirror: 'mi',
|
|
29
30
|
rotate: 'ro',
|
|
30
31
|
brightness: 'br',
|
|
31
32
|
contrast: 'cn',
|
|
32
33
|
dither565: 'dt',
|
|
34
|
+
dither16: 'dt',
|
|
33
35
|
greyscale: 'gr',
|
|
36
|
+
grayscale: 'gr',
|
|
34
37
|
invert: 'in',
|
|
35
38
|
normalize: 'no',
|
|
36
39
|
fade: 'fa',
|
|
@@ -43,7 +46,19 @@ const METHOD_ALIAS = {
|
|
|
43
46
|
sepia: 'se',
|
|
44
47
|
pixelate: 'px',
|
|
45
48
|
displace: 'dp',
|
|
46
|
-
color: 'co'
|
|
49
|
+
color: 'co',
|
|
50
|
+
colour: 'co',
|
|
51
|
+
backgroundQuiet: 'bq',
|
|
52
|
+
circle: 'ci',
|
|
53
|
+
colorType: 'ce',
|
|
54
|
+
cropQuiet: 'cq',
|
|
55
|
+
deflateLevel: 'dl',
|
|
56
|
+
deflateStrategy: 'ds',
|
|
57
|
+
fishEye: 'fe',
|
|
58
|
+
filterType: 'ft',
|
|
59
|
+
rgba: 'rg',
|
|
60
|
+
shadow: 'sh',
|
|
61
|
+
threshold: 'th'
|
|
47
62
|
};
|
|
48
63
|
function getMethodName(value) {
|
|
49
64
|
const name = value.toLowerCase();
|
|
@@ -260,32 +275,31 @@ class JimpHandler {
|
|
|
260
275
|
return;
|
|
261
276
|
}
|
|
262
277
|
const data = this.instance.methodData;
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
278
|
+
if (data) {
|
|
279
|
+
const handler = this.handler;
|
|
280
|
+
for (const [name, args = []] of data) {
|
|
281
|
+
try {
|
|
282
|
+
const alias = getMethodName(name);
|
|
283
|
+
if (!alias) {
|
|
284
|
+
throw (0, types_1.errorValue)("Invalid method name" /* ERR_IMAGE.METHOD_NAME */, name);
|
|
285
|
+
}
|
|
286
|
+
if (alias === 'composite') {
|
|
287
|
+
const [src, x, y, opts] = args;
|
|
288
|
+
if ((0, types_1.isString)(src) && typeof x === 'number' && typeof y === 'number') {
|
|
289
|
+
handler.composite(await jimp.read(src), x, y, opts);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
throw (0, types_1.errorValue)("Invalid parameters" /* ERR_MESSAGE.PARAMETERS */, alias);
|
|
293
|
+
}
|
|
277
294
|
}
|
|
278
295
|
else {
|
|
279
|
-
|
|
296
|
+
handler[alias](...args);
|
|
280
297
|
}
|
|
281
298
|
}
|
|
282
|
-
|
|
283
|
-
|
|
299
|
+
catch (err) {
|
|
300
|
+
this.instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, "jimp" /* STRINGS.MODULE_NAME */ + ': ' + name], err, 2048 /* LOG_TYPE.IMAGE */);
|
|
284
301
|
}
|
|
285
302
|
}
|
|
286
|
-
catch (err) {
|
|
287
|
-
this.instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, "jimp" /* STRINGS.MODULE_NAME */ + ': ' + name], err, 2048 /* LOG_TYPE.IMAGE */);
|
|
288
|
-
}
|
|
289
303
|
}
|
|
290
304
|
}
|
|
291
305
|
resize() {
|
|
@@ -293,64 +307,63 @@ class JimpHandler {
|
|
|
293
307
|
return;
|
|
294
308
|
}
|
|
295
309
|
const data = this.instance.resizeData;
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
break;
|
|
310
|
+
if (data) {
|
|
311
|
+
const { width, height, color, algorithm, align, mode } = data;
|
|
312
|
+
const handler = this.handler;
|
|
313
|
+
if (!isNaN(color)) {
|
|
314
|
+
handler.background(color);
|
|
315
|
+
}
|
|
316
|
+
let resizeMode = jimp.RESIZE_NEAREST_NEIGHBOR, flags = 0;
|
|
317
|
+
switch (algorithm) {
|
|
318
|
+
case 'bilinear':
|
|
319
|
+
resizeMode = jimp.RESIZE_BILINEAR;
|
|
320
|
+
break;
|
|
321
|
+
case 'bicubic':
|
|
322
|
+
resizeMode = jimp.RESIZE_BICUBIC;
|
|
323
|
+
break;
|
|
324
|
+
case 'hermite':
|
|
325
|
+
resizeMode = jimp.RESIZE_HERMITE;
|
|
326
|
+
break;
|
|
327
|
+
case 'bezier':
|
|
328
|
+
resizeMode = jimp.RESIZE_BEZIER;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
switch (align[0]) {
|
|
332
|
+
case 'left':
|
|
333
|
+
flags |= jimp.HORIZONTAL_ALIGN_LEFT;
|
|
334
|
+
break;
|
|
335
|
+
case 'center':
|
|
336
|
+
flags |= jimp.HORIZONTAL_ALIGN_CENTER;
|
|
337
|
+
break;
|
|
338
|
+
case 'right':
|
|
339
|
+
flags |= jimp.HORIZONTAL_ALIGN_RIGHT;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
switch (align[1]) {
|
|
343
|
+
case 'top':
|
|
344
|
+
flags |= jimp.VERTICAL_ALIGN_TOP;
|
|
345
|
+
break;
|
|
346
|
+
case 'middle':
|
|
347
|
+
flags |= jimp.VERTICAL_ALIGN_MIDDLE;
|
|
348
|
+
break;
|
|
349
|
+
case 'bottom':
|
|
350
|
+
flags |= jimp.VERTICAL_ALIGN_BOTTOM;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
switch (mode) {
|
|
354
|
+
case 'contain':
|
|
355
|
+
handler.contain(width, height, flags);
|
|
356
|
+
break;
|
|
357
|
+
case 'cover':
|
|
358
|
+
handler.cover(width, height, flags);
|
|
359
|
+
break;
|
|
360
|
+
case 'scale':
|
|
361
|
+
handler.scaleToFit(width, height);
|
|
362
|
+
break;
|
|
363
|
+
default:
|
|
364
|
+
handler.resize(width === Infinity ? jimp.AUTO : width, height === Infinity ? jimp.AUTO : height, resizeMode);
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
354
367
|
}
|
|
355
368
|
}
|
|
356
369
|
background(value) {
|
|
@@ -874,9 +887,6 @@ class Jimp extends Image {
|
|
|
874
887
|
try {
|
|
875
888
|
const webp = new (require('node-webpmux').Image)();
|
|
876
889
|
loaded = true;
|
|
877
|
-
if (Image.supported(18, 1)) {
|
|
878
|
-
this.formatMessage(2048 /* LOG_TYPE.IMAGE */, 'WARN', 'node-webpmux is not compatible with global fetch', 'NodeJS: --no-experimental-fetch', { ...Image.LOG_STYLE_WARN });
|
|
879
|
-
}
|
|
880
890
|
await webp.initLib();
|
|
881
891
|
await webp.load(host.getBuffer(file));
|
|
882
892
|
if (!(webp.hasAnim && (outputType === "image/webp" /* STRINGS.MIME_WEBP */ || outputType === jimp.MIME_GIF))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/jimp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.7.0",
|
|
24
|
+
"@e-mc/types": "^0.7.0",
|
|
25
25
|
"bmp-js": "^0.1.0",
|
|
26
26
|
"gifwrap": "^0.10.1",
|
|
27
27
|
"jimp": "^0.22.10"
|