cyberchef 10.22.1 → 10.23.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 (101) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/CONTRIBUTING.md +37 -0
  3. package/Dockerfile +2 -0
  4. package/Gruntfile.js +0 -12
  5. package/README.md +1 -1
  6. package/babel.config.js +0 -6
  7. package/package.json +63 -62
  8. package/src/core/Chef.mjs +8 -1
  9. package/src/core/Ingredient.mjs +5 -2
  10. package/src/core/Operation.mjs +6 -1
  11. package/src/core/Recipe.mjs +10 -5
  12. package/src/core/config/Categories.json +18 -3
  13. package/src/core/config/OperationConfig.json +496 -23
  14. package/src/core/config/modules/Ciphers.mjs +6 -0
  15. package/src/core/config/modules/Crypto.mjs +6 -0
  16. package/src/core/config/modules/Default.mjs +6 -0
  17. package/src/core/config/modules/Shellcode.mjs +2 -0
  18. package/src/core/lib/AudioBytes.mjs +103 -0
  19. package/src/core/lib/AudioMetaSchema.mjs +82 -0
  20. package/src/core/lib/AudioParsers.mjs +630 -0
  21. package/src/core/lib/BigIntUtils.mjs +73 -0
  22. package/src/core/lib/Modhex.mjs +2 -0
  23. package/src/core/lib/QRCode.mjs +30 -10
  24. package/src/core/lib/RC6.mjs +625 -0
  25. package/src/core/operations/A1Z26CipherDecode.mjs +1 -1
  26. package/src/core/operations/AddTextToImage.mjs +116 -64
  27. package/src/core/operations/BlurImage.mjs +10 -12
  28. package/src/core/operations/ContainImage.mjs +50 -40
  29. package/src/core/operations/ConvertImageFormat.mjs +33 -39
  30. package/src/core/operations/CoverImage.mjs +39 -37
  31. package/src/core/operations/CropImage.mjs +35 -21
  32. package/src/core/operations/DisassembleARM.mjs +193 -0
  33. package/src/core/operations/DitherImage.mjs +8 -8
  34. package/src/core/operations/EscapeUnicodeCharacters.mjs +0 -17
  35. package/src/core/operations/ExtractAudioMetadata.mjs +175 -0
  36. package/src/core/operations/ExtractLSB.mjs +17 -11
  37. package/src/core/operations/ExtractRGBA.mjs +12 -10
  38. package/src/core/operations/FlaskSessionDecode.mjs +80 -0
  39. package/src/core/operations/FlaskSessionSign.mjs +89 -0
  40. package/src/core/operations/FlaskSessionVerify.mjs +136 -0
  41. package/src/core/operations/FlipImage.mjs +14 -10
  42. package/src/core/operations/GenerateImage.mjs +39 -32
  43. package/src/core/operations/ImageBrightnessContrast.mjs +10 -10
  44. package/src/core/operations/ImageFilter.mjs +14 -13
  45. package/src/core/operations/ImageHueSaturationLightness.mjs +22 -20
  46. package/src/core/operations/ImageOpacity.mjs +6 -8
  47. package/src/core/operations/InvertImage.mjs +4 -6
  48. package/src/core/operations/Jq.mjs +12 -4
  49. package/src/core/operations/NormaliseImage.mjs +5 -7
  50. package/src/core/operations/OffsetChecker.mjs +1 -1
  51. package/src/core/operations/ParseEthernetFrame.mjs +112 -0
  52. package/src/core/operations/ParseIPv4Header.mjs +23 -6
  53. package/src/core/operations/ParseQRCode.mjs +13 -13
  54. package/src/core/operations/PseudoRandomIntegerGenerator.mjs +164 -0
  55. package/src/core/operations/RC6Decrypt.mjs +119 -0
  56. package/src/core/operations/RC6Encrypt.mjs +119 -0
  57. package/src/core/operations/RandomizeColourPalette.mjs +11 -11
  58. package/src/core/operations/ResizeImage.mjs +30 -23
  59. package/src/core/operations/RotateImage.mjs +8 -9
  60. package/src/core/operations/SQLBeautify.mjs +21 -3
  61. package/src/core/operations/SharpenImage.mjs +94 -62
  62. package/src/core/operations/SplitColourChannels.mjs +47 -21
  63. package/src/core/operations/TextIntegerConverter.mjs +123 -0
  64. package/src/core/operations/UnescapeUnicodeCharacters.mjs +17 -0
  65. package/src/core/operations/ViewBitPlane.mjs +16 -20
  66. package/src/core/operations/index.mjs +20 -0
  67. package/src/node/index.mjs +50 -0
  68. package/src/web/HTMLIngredient.mjs +24 -43
  69. package/src/web/Manager.mjs +1 -0
  70. package/src/web/html/index.html +6 -6
  71. package/src/web/static/fonts/bmfonts/Roboto72White.fnt +491 -485
  72. package/src/web/static/fonts/bmfonts/RobotoBlack72White.fnt +494 -488
  73. package/src/web/static/fonts/bmfonts/RobotoMono72White.fnt +110 -103
  74. package/src/web/static/fonts/bmfonts/RobotoSlab72White.fnt +498 -492
  75. package/src/web/stylesheets/layout/_banner.css +30 -0
  76. package/src/web/stylesheets/layout/_modals.css +5 -0
  77. package/src/web/stylesheets/utils/_overrides.css +7 -0
  78. package/src/web/waiters/ControlsWaiter.mjs +82 -0
  79. package/src/web/waiters/InputWaiter.mjs +12 -6
  80. package/src/web/waiters/RecipeWaiter.mjs +2 -2
  81. package/tests/browser/02_ops.js +23 -3
  82. package/tests/node/index.mjs +1 -0
  83. package/tests/node/tests/lib/BigIntUtils.mjs +150 -0
  84. package/tests/node/tests/operations.mjs +9 -7
  85. package/tests/operations/index.mjs +8 -0
  86. package/tests/operations/tests/A1Z26CipherDecode.mjs +33 -0
  87. package/tests/operations/tests/DisassembleARM.mjs +377 -0
  88. package/tests/operations/tests/ExtractAudioMetadata.mjs +287 -0
  89. package/tests/operations/tests/FlaskSession.mjs +246 -0
  90. package/tests/operations/tests/GenerateQRCode.mjs +67 -0
  91. package/tests/operations/tests/JWTSign.mjs +83 -8
  92. package/tests/operations/tests/Jq.mjs +32 -0
  93. package/tests/operations/tests/Modhex.mjs +20 -0
  94. package/tests/operations/tests/ParseEthernetFrame.mjs +45 -0
  95. package/tests/operations/tests/RC6.mjs +487 -0
  96. package/tests/operations/tests/SQLBeautify.mjs +54 -0
  97. package/tests/operations/tests/TextIntegerConverter.mjs +199 -0
  98. package/tests/samples/Audio.mjs +73 -0
  99. package/tests/samples/Images.mjs +0 -12
  100. package/webpack.config.js +10 -7
  101. package/src/core/lib/ImageManipulation.mjs +0 -251
@@ -9,13 +9,19 @@ import OperationError from "../errors/OperationError.mjs";
9
9
  import { isImage } from "../lib/FileType.mjs";
10
10
  import { toBase64 } from "../lib/Base64.mjs";
11
11
  import { isWorkerEnvironment } from "../Utils.mjs";
12
- import Jimp from "jimp/es/index.js";
12
+ import {
13
+ Jimp,
14
+ JimpMime,
15
+ ResizeStrategy,
16
+ measureText,
17
+ measureTextHeight,
18
+ loadFont,
19
+ } from "jimp";
13
20
 
14
21
  /**
15
22
  * Add Text To Image operation
16
23
  */
17
24
  class AddTextToImage extends Operation {
18
-
19
25
  /**
20
26
  * AddTextToImage constructor
21
27
  */
@@ -24,7 +30,8 @@ class AddTextToImage extends Operation {
24
30
 
25
31
  this.name = "Add Text To Image";
26
32
  this.module = "Image";
27
- this.description = "Adds text onto an image.<br><br>Text can be horizontally or vertically aligned, or the position can be manually specified.<br>Variants of the Roboto font face are available in any size or colour.";
33
+ this.description =
34
+ "Adds text onto an image.<br><br>Text can be horizontally or vertically aligned, or the position can be manually specified.<br>Variants of the Roboto font face are available in any size or colour.";
28
35
  this.infoURL = "";
29
36
  this.inputType = "ArrayBuffer";
30
37
  this.outputType = "ArrayBuffer";
@@ -33,72 +40,67 @@ class AddTextToImage extends Operation {
33
40
  {
34
41
  name: "Text",
35
42
  type: "string",
36
- value: ""
43
+ value: "",
37
44
  },
38
45
  {
39
46
  name: "Horizontal align",
40
47
  type: "option",
41
- value: ["None", "Left", "Center", "Right"]
48
+ value: ["None", "Left", "Center", "Right"],
42
49
  },
43
50
  {
44
51
  name: "Vertical align",
45
52
  type: "option",
46
- value: ["None", "Top", "Middle", "Bottom"]
53
+ value: ["None", "Top", "Middle", "Bottom"],
47
54
  },
48
55
  {
49
56
  name: "X position",
50
57
  type: "number",
51
- value: 0
58
+ value: 0,
52
59
  },
53
60
  {
54
61
  name: "Y position",
55
62
  type: "number",
56
- value: 0
63
+ value: 0,
57
64
  },
58
65
  {
59
66
  name: "Size",
60
67
  type: "number",
61
68
  value: 32,
62
- min: 8
69
+ min: 8,
63
70
  },
64
71
  {
65
72
  name: "Font face",
66
73
  type: "option",
67
- value: [
68
- "Roboto",
69
- "Roboto Black",
70
- "Roboto Mono",
71
- "Roboto Slab"
72
- ]
74
+ value: ["Roboto", "Roboto Black", "Roboto Mono", "Roboto Slab"],
73
75
  },
74
76
  {
75
77
  name: "Red",
76
78
  type: "number",
77
79
  value: 255,
78
80
  min: 0,
79
- max: 255
81
+ max: 255,
80
82
  },
81
83
  {
82
84
  name: "Green",
83
85
  type: "number",
84
86
  value: 255,
85
87
  min: 0,
86
- max: 255
88
+ max: 255,
87
89
  },
88
90
  {
89
91
  name: "Blue",
90
92
  type: "number",
91
93
  value: 255,
92
94
  min: 0,
93
- max: 255
95
+ max: 255,
94
96
  },
95
97
  {
96
98
  name: "Alpha",
97
99
  type: "number",
98
100
  value: 255,
99
101
  min: 0,
100
- max: 255
101
- }
102
+ max: 255,
103
+ },
102
104
  ];
103
105
  }
104
106
 
@@ -131,41 +133,60 @@ class AddTextToImage extends Operation {
131
133
  } catch (err) {
132
134
  throw new OperationError(`Error loading image. (${err})`);
133
135
  }
134
- try {
135
- if (isWorkerEnvironment())
136
- self.sendStatusMessage("Adding text to image...");
137
136
 
138
- const fontsMap = {};
137
+ if (isWorkerEnvironment())
138
+ self.sendStatusMessage("Adding text to image...");
139
+
140
+ const fontsMap = {};
141
+ try {
139
142
  const fonts = [
140
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/Roboto72White.fnt"),
141
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoBlack72White.fnt"),
142
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoMono72White.fnt"),
143
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoSlab72White.fnt")
143
+ import(
144
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/Roboto72White.fnt"
145
+ ),
146
+ import(
147
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoBlack72White.fnt"
148
+ ),
149
+ import(
150
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoMono72White.fnt"
151
+ ),
152
+ import(
153
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoSlab72White.fnt"
154
+ ),
144
155
  ];
145
156
 
146
- await Promise.all(fonts)
147
- .then(fonts => {
148
- fontsMap.Roboto = fonts[0];
149
- fontsMap["Roboto Black"] = fonts[1];
150
- fontsMap["Roboto Mono"] = fonts[2];
151
- fontsMap["Roboto Slab"] = fonts[3];
152
- });
153
-
154
-
157
+ await Promise.all(fonts).then((fonts) => {
158
+ fontsMap.Roboto = fonts[0];
159
+ fontsMap["Roboto Black"] = fonts[1];
160
+ fontsMap["Roboto Mono"] = fonts[2];
161
+ fontsMap["Roboto Slab"] = fonts[3];
162
+ });
155
163
  // Make Webpack load the png font images
156
164
  await Promise.all([
157
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/Roboto72White.png"),
158
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoSlab72White.png"),
159
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoMono72White.png"),
160
- import(/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoBlack72White.png")
165
+ import(
166
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/Roboto72White.png"
167
+ ),
168
+ import(
169
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoSlab72White.png"
170
+ ),
171
+ import(
172
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoMono72White.png"
173
+ ),
174
+ import(
175
+ /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoBlack72White.png"
176
+ ),
161
177
  ]);
178
+ } catch (err) {
179
+ throw new OperationError(`Error preparing fonts. (${err})`);
180
+ }
162
181
 
182
+ let jimpFont;
183
+ try {
163
184
  const font = fontsMap[fontFace];
164
185
 
165
186
  // LoadFont needs an absolute url, so append the font name to self.docURL
166
- const jimpFont = await Jimp.loadFont(self.docURL + "/" + font.default);
187
+ jimpFont = await loadFont(self.docURL + "/" + font.default);
167
188
 
168
- jimpFont.pages.forEach(function(page) {
189
+ jimpFont.pages.forEach(function (page) {
169
190
  if (page.bitmap) {
170
191
  // Adjust the RGB values of the image pages to change the font colour.
171
192
  const pageWidth = page.bitmap.width;
@@ -175,32 +196,56 @@ class AddTextToImage extends Operation {
175
196
  const idx = (iy * pageWidth + ix) << 2;
176
197
 
177
198
  const newRed = page.bitmap.data[idx] - (255 - red);
178
- const newGreen = page.bitmap.data[idx + 1] - (255 - green);
179
- const newBlue = page.bitmap.data[idx + 2] - (255 - blue);
180
- const newAlpha = page.bitmap.data[idx + 3] - (255 - alpha);
199
+ const newGreen =
200
+ page.bitmap.data[idx + 1] - (255 - green);
201
+ const newBlue =
202
+ page.bitmap.data[idx + 2] - (255 - blue);
203
+ const newAlpha =
204
+ page.bitmap.data[idx + 3] - (255 - alpha);
181
205
 
182
206
  // Make sure the bitmap values don't go below 0 as that makes jimp very unhappy
183
- page.bitmap.data[idx] = (newRed > 0) ? newRed : 0;
184
- page.bitmap.data[idx + 1] = (newGreen > 0) ? newGreen : 0;
185
- page.bitmap.data[idx + 2] = (newBlue > 0) ? newBlue : 0;
186
- page.bitmap.data[idx + 3] = (newAlpha > 0) ? newAlpha : 0;
207
+ page.bitmap.data[idx] = newRed > 0 ? newRed : 0;
208
+ page.bitmap.data[idx + 1] =
209
+ newGreen > 0 ? newGreen : 0;
210
+ page.bitmap.data[idx + 2] =
211
+ newBlue > 0 ? newBlue : 0;
212
+ page.bitmap.data[idx + 3] =
213
+ newAlpha > 0 ? newAlpha : 0;
187
214
  }
188
215
  }
189
216
  }
190
217
  });
218
+ } catch (err) {
219
+ throw new OperationError(`Error loading font. (${err})`);
220
+ }
191
221
 
222
+ try {
192
223
  // Create a temporary image to hold the rendered text
193
- const textImage = new Jimp(Jimp.measureText(jimpFont, text), Jimp.measureTextHeight(jimpFont, text));
194
- textImage.print(jimpFont, 0, 0, text);
224
+ const textImage = new Jimp({
225
+ width: measureText(jimpFont, text),
226
+ height: measureTextHeight(jimpFont, text),
227
+ });
228
+ textImage.print({
229
+ font: jimpFont,
230
+ x: 0,
231
+ y: 0,
232
+ text,
233
+ });
195
234
 
196
235
  // Scale the rendered text image to the correct size
197
236
  const scaleFactor = size / 72;
198
237
  if (size !== 1) {
199
238
  // Use bicubic for decreasing size
200
239
  if (size > 1) {
201
- textImage.scale(scaleFactor, Jimp.RESIZE_BICUBIC);
240
+ textImage.scale({
241
+ f: scaleFactor,
242
+ mode: ResizeStrategy.BICUBIC,
243
+ });
202
244
  } else {
203
- textImage.scale(scaleFactor, Jimp.RESIZE_BILINEAR);
245
+ textImage.scale({
246
+ f: scaleFactor,
247
+ mode: ResizeStrategy.BILINEAR,
248
+ });
204
249
  }
205
250
  }
206
251
 
@@ -210,10 +255,10 @@ class AddTextToImage extends Operation {
210
255
  xPos = 0;
211
256
  break;
212
257
  case "Center":
213
- xPos = (image.getWidth() / 2) - (textImage.getWidth() / 2);
258
+ xPos = image.width / 2 - textImage.width / 2;
214
259
  break;
215
260
  case "Right":
216
- xPos = image.getWidth() - textImage.getWidth();
261
+ xPos = image.width - textImage.width;
217
262
  break;
218
263
  }
219
264
 
@@ -222,25 +267,33 @@ class AddTextToImage extends Operation {
222
267
  yPos = 0;
223
268
  break;
224
269
  case "Middle":
225
- yPos = (image.getHeight() / 2) - (textImage.getHeight() / 2);
270
+ yPos = image.height / 2 - textImage.height / 2;
226
271
  break;
227
272
  case "Bottom":
228
- yPos = image.getHeight() - textImage.getHeight();
273
+ yPos = image.height - textImage.height;
229
274
  break;
230
275
  }
231
276
 
232
277
  // Blit the rendered text image onto the original source image
233
- image.blit(textImage, xPos, yPos);
278
+ image.blit({
279
+ src: textImage,
280
+ x: xPos,
281
+ y: yPos,
282
+ });
283
+ } catch (err) {
284
+ throw new OperationError(`Error adding text to image. (${err})`);
285
+ }
234
286
 
287
+ try {
235
288
  let imageBuffer;
236
- if (image.getMIME() === "image/gif") {
237
- imageBuffer = await image.getBufferAsync(Jimp.MIME_PNG);
289
+ if (image.mime === "image/gif") {
290
+ imageBuffer = await image.getBuffer(JimpMime.png);
238
291
  } else {
239
- imageBuffer = await image.getBufferAsync(Jimp.AUTO);
292
+ imageBuffer = await image.getBuffer(image.mime);
240
293
  }
241
294
  return imageBuffer.buffer;
242
295
  } catch (err) {
243
- throw new OperationError(`Error adding text to image. (${err})`);
296
+ throw new OperationError(`Error exporting image. (${err})`);
244
297
  }
245
298
  }
246
299
 
@@ -261,7 +314,6 @@ class AddTextToImage extends Operation {
261
314
 
262
315
  return `<img src="data:${type};base64,${toBase64(dataArray)}">`;
263
316
  }
264
-
265
317
  }
266
318
 
267
319
  export default AddTextToImage;
@@ -9,14 +9,12 @@ import OperationError from "../errors/OperationError.mjs";
9
9
  import { isWorkerEnvironment } from "../Utils.mjs";
10
10
  import { isImage } from "../lib/FileType.mjs";
11
11
  import { toBase64 } from "../lib/Base64.mjs";
12
- import { gaussianBlur } from "../lib/ImageManipulation.mjs";
13
- import Jimp from "jimp/es/index.js";
12
+ import { Jimp, JimpMime } from "jimp";
14
13
 
15
14
  /**
16
15
  * Blur Image operation
17
16
  */
18
17
  class BlurImage extends Operation {
19
-
20
18
  /**
21
19
  * BlurImage constructor
22
20
  */
@@ -25,7 +23,8 @@ class BlurImage extends Operation {
25
23
 
26
24
  this.name = "Blur Image";
27
25
  this.module = "Image";
28
- this.description = "Applies a blur effect to the image.<br><br>Gaussian blur is much slower than fast blur, but produces better results.";
26
+ this.description =
27
+ "Applies a blur effect to the image.<br><br>Gaussian blur is much slower than fast blur, but produces better results.";
29
28
  this.infoURL = "https://wikipedia.org/wiki/Gaussian_blur";
30
29
  this.inputType = "ArrayBuffer";
31
30
  this.outputType = "ArrayBuffer";
@@ -35,13 +34,13 @@ class BlurImage extends Operation {
35
34
  name: "Amount",
36
35
  type: "number",
37
36
  value: 5,
38
- min: 1
37
+ min: 1,
39
38
  },
40
39
  {
41
40
  name: "Type",
42
41
  type: "option",
43
- value: ["Fast", "Gaussian"]
44
- }
42
+ value: ["Fast", "Gaussian"],
43
+ },
45
44
  ];
46
45
  }
47
46
 
@@ -73,15 +72,15 @@ class BlurImage extends Operation {
73
72
  case "Gaussian":
74
73
  if (isWorkerEnvironment())
75
74
  self.sendStatusMessage("Gaussian blurring image...");
76
- image = gaussianBlur(image, blurAmount);
75
+ image.gaussian(blurAmount);
77
76
  break;
78
77
  }
79
78
 
80
79
  let imageBuffer;
81
- if (image.getMIME() === "image/gif") {
82
- imageBuffer = await image.getBufferAsync(Jimp.MIME_PNG);
80
+ if (image.mime === "image/gif") {
81
+ imageBuffer = await image.getBuffer(JimpMime.png);
83
82
  } else {
84
- imageBuffer = await image.getBufferAsync(Jimp.AUTO);
83
+ imageBuffer = await image.getBuffer(image.mime);
85
84
  }
86
85
  return imageBuffer.buffer;
87
86
  } catch (err) {
@@ -106,7 +105,6 @@ class BlurImage extends Operation {
106
105
 
107
106
  return `<img src="data:${type};base64,${toBase64(dataArray)}">`;
108
107
  }
109
-
110
108
  }
111
109
 
112
110
  export default BlurImage;
@@ -9,13 +9,18 @@ import OperationError from "../errors/OperationError.mjs";
9
9
  import { isImage } from "../lib/FileType.mjs";
10
10
  import { toBase64 } from "../lib/Base64.mjs";
11
11
  import { isWorkerEnvironment } from "../Utils.mjs";
12
- import Jimp from "jimp/es/index.js";
12
+ import {
13
+ Jimp,
14
+ JimpMime,
15
+ ResizeStrategy,
16
+ HorizontalAlign,
17
+ VerticalAlign,
18
+ } from "jimp";
13
19
 
14
20
  /**
15
21
  * Contain Image operation
16
22
  */
17
23
  class ContainImage extends Operation {
18
-
19
24
  /**
20
25
  * ContainImage constructor
21
26
  */
@@ -24,7 +29,8 @@ class ContainImage extends Operation {
24
29
 
25
30
  this.name = "Contain Image";
26
31
  this.module = "Image";
27
- this.description = "Scales an image to the specified width and height, maintaining the aspect ratio. The image may be letterboxed.";
32
+ this.description =
33
+ "Scales an image to the specified width and height, maintaining the aspect ratio. The image may be letterboxed.";
28
34
  this.infoURL = "";
29
35
  this.inputType = "ArrayBuffer";
30
36
  this.outputType = "ArrayBuffer";
@@ -34,33 +40,25 @@ class ContainImage extends Operation {
34
40
  name: "Width",
35
41
  type: "number",
36
42
  value: 100,
37
- min: 1
43
+ min: 1,
38
44
  },
39
45
  {
40
46
  name: "Height",
41
47
  type: "number",
42
48
  value: 100,
43
- min: 1
49
+ min: 1,
44
50
  },
45
51
  {
46
52
  name: "Horizontal align",
47
53
  type: "option",
48
- value: [
49
- "Left",
50
- "Center",
51
- "Right"
52
- ],
53
- defaultIndex: 1
54
+ value: ["Left", "Center", "Right"],
55
+ defaultIndex: 1,
54
56
  },
55
57
  {
56
58
  name: "Vertical align",
57
59
  type: "option",
58
- value: [
59
- "Top",
60
- "Middle",
61
- "Bottom"
62
- ],
63
- defaultIndex: 1
60
+ value: ["Top", "Middle", "Bottom"],
61
+ defaultIndex: 1,
64
62
  },
65
63
  {
66
64
  name: "Resizing algorithm",
@@ -70,15 +68,15 @@ class ContainImage extends Operation {
70
68
  "Bilinear",
71
69
  "Bicubic",
72
70
  "Hermite",
73
- "Bezier"
71
+ "Bezier",
74
72
  ],
75
- defaultIndex: 1
73
+ defaultIndex: 1,
76
74
  },
77
75
  {
78
76
  name: "Opaque background",
79
77
  type: "boolean",
80
- value: true
81
- }
78
+ value: true,
79
+ },
82
80
  ];
83
81
  }
84
82
 
@@ -91,20 +89,20 @@ class ContainImage extends Operation {
91
89
  const [width, height, hAlign, vAlign, alg, opaqueBg] = args;
92
90
 
93
91
  const resizeMap = {
94
- "Nearest Neighbour": Jimp.RESIZE_NEAREST_NEIGHBOR,
95
- "Bilinear": Jimp.RESIZE_BILINEAR,
96
- "Bicubic": Jimp.RESIZE_BICUBIC,
97
- "Hermite": Jimp.RESIZE_HERMITE,
98
- "Bezier": Jimp.RESIZE_BEZIER
92
+ "Nearest Neighbour": ResizeStrategy.NEAREST_NEIGHBOR,
93
+ Bilinear: ResizeStrategy.BILINEAR,
94
+ Bicubic: ResizeStrategy.BICUBIC,
95
+ Hermite: ResizeStrategy.HERMITE,
96
+ Bezier: ResizeStrategy.BEZIER,
99
97
  };
100
98
 
101
99
  const alignMap = {
102
- "Left": Jimp.HORIZONTAL_ALIGN_LEFT,
103
- "Center": Jimp.HORIZONTAL_ALIGN_CENTER,
104
- "Right": Jimp.HORIZONTAL_ALIGN_RIGHT,
105
- "Top": Jimp.VERTICAL_ALIGN_TOP,
106
- "Middle": Jimp.VERTICAL_ALIGN_MIDDLE,
107
- "Bottom": Jimp.VERTICAL_ALIGN_BOTTOM
100
+ Left: HorizontalAlign.LEFT,
101
+ Center: HorizontalAlign.CENTER,
102
+ Right: HorizontalAlign.RIGHT,
103
+ Top: VerticalAlign.TOP,
104
+ Middle: VerticalAlign.MIDDLE,
105
+ Bottom: VerticalAlign.BOTTOM,
108
106
  };
109
107
 
110
108
  if (!isImage(input)) {
@@ -117,22 +115,35 @@ class ContainImage extends Operation {
117
115
  } catch (err) {
118
116
  throw new OperationError(`Error loading image. (${err})`);
119
117
  }
118
+ const originalMime = image.mime;
120
119
  try {
121
120
  if (isWorkerEnvironment())
122
121
  self.sendStatusMessage("Containing image...");
123
- image.contain(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
122
+ image.contain({
123
+ w: width,
124
+ h: height,
125
+ align: alignMap[hAlign] | alignMap[vAlign],
126
+ mode: resizeMap[alg],
127
+ });
124
128
 
125
129
  if (opaqueBg) {
126
- const newImage = await Jimp.read(width, height, 0x000000FF);
127
- newImage.blit(image, 0, 0);
128
- image = newImage;
130
+ const newImage = new Jimp({
131
+ width,
132
+ height,
133
+ color: 0x000000ff,
134
+ });
135
+ image = newImage.blit({
136
+ src: image,
137
+ x: 0,
138
+ y: 0,
139
+ });
129
140
  }
130
141
 
131
142
  let imageBuffer;
132
- if (image.getMIME() === "image/gif") {
133
- imageBuffer = await image.getBufferAsync(Jimp.MIME_PNG);
143
+ if (originalMime === "image/gif") {
144
+ imageBuffer = await image.getBuffer(JimpMime.png);
134
145
  } else {
135
- imageBuffer = await image.getBufferAsync(Jimp.AUTO);
146
+ imageBuffer = await image.getBuffer(originalMime);
136
147
  }
137
148
  return imageBuffer.buffer;
138
149
  } catch (err) {
@@ -156,7 +167,6 @@ class ContainImage extends Operation {
156
167
 
157
168
  return `<img src="data:${type};base64,${toBase64(dataArray)}">`;
158
169
  }
159
-
160
170
  }
161
171
 
162
172
  export default ContainImage;