@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.
- package/index.js +76 -81
- 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 (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
|
|
296
|
+
handler[alias](...args);
|
|
295
297
|
}
|
|
296
298
|
}
|
|
297
|
-
|
|
298
|
-
|
|
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 (
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
+
"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"
|