@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.
Files changed (2) hide show
  1. package/index.js +92 -82
  2. 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 (!data) {
264
- return;
265
- }
266
- const handler = this.handler;
267
- for (const [name, args = []] of data) {
268
- try {
269
- const alias = getMethodName(name);
270
- if (!alias) {
271
- throw (0, types_1.errorValue)("Invalid method name" /* ERR_IMAGE.METHOD_NAME */, name);
272
- }
273
- if (alias === 'composite') {
274
- const [src, x, y, opts] = args;
275
- if ((0, types_1.isString)(src) && typeof x === 'number' && typeof y === 'number') {
276
- handler.composite(await jimp.read(src), x, y, opts);
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
- throw (0, types_1.errorValue)("Invalid parameters" /* ERR_MESSAGE.PARAMETERS */, alias);
296
+ handler[alias](...args);
280
297
  }
281
298
  }
282
- else {
283
- handler[alias](...args);
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 (!data) {
297
- return;
298
- }
299
- const { width, height, color, algorithm, align, mode } = data;
300
- const handler = this.handler;
301
- if (!isNaN(color)) {
302
- handler.background(color);
303
- }
304
- let resizeMode = jimp.RESIZE_NEAREST_NEIGHBOR, flags = 0;
305
- switch (algorithm) {
306
- case 'bilinear':
307
- resizeMode = jimp.RESIZE_BILINEAR;
308
- break;
309
- case 'bicubic':
310
- resizeMode = jimp.RESIZE_BICUBIC;
311
- break;
312
- case 'hermite':
313
- resizeMode = jimp.RESIZE_HERMITE;
314
- break;
315
- case 'bezier':
316
- resizeMode = jimp.RESIZE_BEZIER;
317
- break;
318
- }
319
- switch (align[0]) {
320
- case 'left':
321
- flags |= jimp.HORIZONTAL_ALIGN_LEFT;
322
- break;
323
- case 'center':
324
- flags |= jimp.HORIZONTAL_ALIGN_CENTER;
325
- break;
326
- case 'right':
327
- flags |= jimp.HORIZONTAL_ALIGN_RIGHT;
328
- break;
329
- }
330
- switch (align[1]) {
331
- case 'top':
332
- flags |= jimp.VERTICAL_ALIGN_TOP;
333
- break;
334
- case 'middle':
335
- flags |= jimp.VERTICAL_ALIGN_MIDDLE;
336
- break;
337
- case 'bottom':
338
- flags |= jimp.VERTICAL_ALIGN_BOTTOM;
339
- break;
340
- }
341
- switch (mode) {
342
- case 'contain':
343
- handler.contain(width, height, flags);
344
- break;
345
- case 'cover':
346
- handler.cover(width, height, flags);
347
- break;
348
- case 'scale':
349
- handler.scaleToFit(width, height);
350
- break;
351
- default:
352
- handler.resize(width === Infinity ? jimp.AUTO : width, height === Infinity ? jimp.AUTO : height, resizeMode);
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.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.6.0",
24
- "@e-mc/types": "^0.6.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"