@pi-r/jimp 0.3.1 → 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 +76 -81
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -275,32 +275,31 @@ class JimpHandler {
275
275
  return;
276
276
  }
277
277
  const data = this.instance.methodData;
278
- if (!data) {
279
- return;
280
- }
281
- const handler = this.handler;
282
- for (const [name, args = []] of data) {
283
- try {
284
- const alias = getMethodName(name);
285
- if (!alias) {
286
- throw (0, types_1.errorValue)("Invalid method name" /* ERR_IMAGE.METHOD_NAME */, name);
287
- }
288
- if (alias === 'composite') {
289
- const [src, x, y, opts] = args;
290
- if ((0, types_1.isString)(src) && typeof x === 'number' && typeof y === 'number') {
291
- 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
+ }
292
294
  }
293
295
  else {
294
- throw (0, types_1.errorValue)("Invalid parameters" /* ERR_MESSAGE.PARAMETERS */, alias);
296
+ handler[alias](...args);
295
297
  }
296
298
  }
297
- else {
298
- handler[alias](...args);
299
+ catch (err) {
300
+ this.instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, "jimp" /* STRINGS.MODULE_NAME */ + ': ' + name], err, 2048 /* LOG_TYPE.IMAGE */);
299
301
  }
300
302
  }
301
- catch (err) {
302
- this.instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, "jimp" /* STRINGS.MODULE_NAME */ + ': ' + name], err, 2048 /* LOG_TYPE.IMAGE */);
303
- }
304
303
  }
305
304
  }
306
305
  resize() {
@@ -308,64 +307,63 @@ class JimpHandler {
308
307
  return;
309
308
  }
310
309
  const data = this.instance.resizeData;
311
- if (!data) {
312
- return;
313
- }
314
- const { width, height, color, algorithm, align, mode } = data;
315
- const handler = this.handler;
316
- if (!isNaN(color)) {
317
- handler.background(color);
318
- }
319
- let resizeMode = jimp.RESIZE_NEAREST_NEIGHBOR, flags = 0;
320
- switch (algorithm) {
321
- case 'bilinear':
322
- resizeMode = jimp.RESIZE_BILINEAR;
323
- break;
324
- case 'bicubic':
325
- resizeMode = jimp.RESIZE_BICUBIC;
326
- break;
327
- case 'hermite':
328
- resizeMode = jimp.RESIZE_HERMITE;
329
- break;
330
- case 'bezier':
331
- resizeMode = jimp.RESIZE_BEZIER;
332
- break;
333
- }
334
- switch (align[0]) {
335
- case 'left':
336
- flags |= jimp.HORIZONTAL_ALIGN_LEFT;
337
- break;
338
- case 'center':
339
- flags |= jimp.HORIZONTAL_ALIGN_CENTER;
340
- break;
341
- case 'right':
342
- flags |= jimp.HORIZONTAL_ALIGN_RIGHT;
343
- break;
344
- }
345
- switch (align[1]) {
346
- case 'top':
347
- flags |= jimp.VERTICAL_ALIGN_TOP;
348
- break;
349
- case 'middle':
350
- flags |= jimp.VERTICAL_ALIGN_MIDDLE;
351
- break;
352
- case 'bottom':
353
- flags |= jimp.VERTICAL_ALIGN_BOTTOM;
354
- break;
355
- }
356
- switch (mode) {
357
- case 'contain':
358
- handler.contain(width, height, flags);
359
- break;
360
- case 'cover':
361
- handler.cover(width, height, flags);
362
- break;
363
- case 'scale':
364
- handler.scaleToFit(width, height);
365
- break;
366
- default:
367
- handler.resize(width === Infinity ? jimp.AUTO : width, height === Infinity ? jimp.AUTO : height, resizeMode);
368
- 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
+ }
369
367
  }
370
368
  }
371
369
  background(value) {
@@ -889,9 +887,6 @@ class Jimp extends Image {
889
887
  try {
890
888
  const webp = new (require('node-webpmux').Image)();
891
889
  loaded = true;
892
- if (Image.supported(18, 1)) {
893
- this.formatMessage(2048 /* LOG_TYPE.IMAGE */, 'WARN', 'node-webpmux is not compatible with global fetch', 'NodeJS: --no-experimental-fetch', { ...Image.LOG_STYLE_WARN });
894
- }
895
890
  await webp.initLib();
896
891
  await webp.load(host.getBuffer(file));
897
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.1",
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"