@midscene/shared 0.11.1-beta-20250214012635.0 → 0.11.2

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.
@@ -67,11 +67,11 @@ declare function transformImgPathToBase64(inputPath: string): Promise<string>;
67
67
  * @returns A Promise that resolves to a base64-encoded string representing the resized image
68
68
  * @throws An error if the width or height cannot be determined from the metadata
69
69
  */
70
- declare function resizeImg(inputData: Buffer, newSize: {
70
+ declare function resizeImg(inputData: Buffer, newSize?: {
71
71
  width: number;
72
72
  height: number;
73
73
  }): Promise<Buffer>;
74
- declare function resizeImgBase64(inputBase64: string, newSize: {
74
+ declare function resizeImgBase64(inputData: string, newSize?: {
75
75
  width: number;
76
76
  height: number;
77
77
  }): Promise<string>;
@@ -87,7 +87,7 @@ declare function resizeImgBase64(inputBase64: string, newSize: {
87
87
  * @returns {Object} An object containing the new width and height.
88
88
  * @throws {Error} Throws an error if the width or height is not a positive number.
89
89
  */
90
- declare function zoomForGPT4o(originalWidth: number, originalHeight: number): {
90
+ declare function calculateNewDimensions(originalWidth: number, originalHeight: number): {
91
91
  width: number;
92
92
  height: number;
93
93
  };
@@ -148,4 +148,4 @@ declare function savePositionImg(options: {
148
148
  outputPath: string;
149
149
  }): Promise<void>;
150
150
 
151
- export { base64Encoded, base64ToPngFormat, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o };
151
+ export { base64Encoded, base64ToPngFormat, bufferFromBase64, calculateNewDimensions, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage };
@@ -54,6 +54,7 @@ __export(img_exports, {
54
54
  base64Encoded: () => base64Encoded,
55
55
  base64ToPngFormat: () => base64ToPngFormat,
56
56
  bufferFromBase64: () => bufferFromBase64,
57
+ calculateNewDimensions: () => calculateNewDimensions,
57
58
  compositeElementInfoImg: () => compositeElementInfoImg,
58
59
  drawBoxOnImage: () => drawBoxOnImage,
59
60
  imageInfo: () => imageInfo,
@@ -64,8 +65,7 @@ __export(img_exports, {
64
65
  saveBase64Image: () => saveBase64Image,
65
66
  savePositionImg: () => savePositionImg,
66
67
  transformImgPathToBase64: () => transformImgPathToBase64,
67
- trimImage: () => trimImage,
68
- zoomForGPT4o: () => zoomForGPT4o
68
+ trimImage: () => trimImage
69
69
  });
70
70
  module.exports = __toCommonJS(img_exports);
71
71
 
@@ -138,7 +138,6 @@ function base64ToPngFormat(base64) {
138
138
  }
139
139
 
140
140
  // src/img/transform.ts
141
- var import_node_assert2 = __toESM(require("assert"));
142
141
  var import_node_buffer2 = require("buffer");
143
142
  function saveBase64Image(options) {
144
143
  return __async(this, null, function* () {
@@ -162,29 +161,27 @@ function resizeImg(inputData, newSize) {
162
161
  return __async(this, null, function* () {
163
162
  if (typeof inputData === "string")
164
163
  throw Error("inputData is base64, use resizeImgBase64 instead");
165
- (0, import_node_assert2.default)(
166
- newSize && newSize.width > 0 && newSize.height > 0,
167
- "newSize must be positive"
168
- );
169
164
  const Jimp = yield getJimp();
170
165
  const image = yield Jimp.read(inputData);
171
166
  const { width, height } = image.bitmap;
172
167
  if (!width || !height) {
173
168
  throw Error("Undefined width or height from the input image.");
174
169
  }
175
- if (newSize.width === width && newSize.height === height) {
176
- return inputData;
177
- }
178
- image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR);
170
+ const finalNewSize = newSize || calculateNewDimensions(width, height);
171
+ image.resize(
172
+ finalNewSize.width,
173
+ finalNewSize.height,
174
+ Jimp.RESIZE_NEAREST_NEIGHBOR
175
+ );
179
176
  image.quality(90);
180
177
  const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG);
181
178
  return resizedBuffer;
182
179
  });
183
180
  }
184
- function resizeImgBase64(inputBase64, newSize) {
181
+ function resizeImgBase64(inputData, newSize) {
185
182
  return __async(this, null, function* () {
186
183
  const splitFlag = ";base64,";
187
- const dataSplitted = inputBase64.split(splitFlag);
184
+ const dataSplitted = inputData.split(splitFlag);
188
185
  if (dataSplitted.length !== 2) {
189
186
  throw Error("Invalid base64 data");
190
187
  }
@@ -194,7 +191,7 @@ function resizeImgBase64(inputBase64, newSize) {
194
191
  return `${dataSplitted[0]}${splitFlag}${content}`;
195
192
  });
196
193
  }
197
- function zoomForGPT4o(originalWidth, originalHeight) {
194
+ function calculateNewDimensions(originalWidth, originalHeight) {
198
195
  const maxWidth = 2048;
199
196
  const maxHeight = 768;
200
197
  let newWidth = originalWidth;
@@ -240,7 +237,7 @@ function trimImage(image) {
240
237
  }
241
238
 
242
239
  // src/img/box-select.ts
243
- var import_node_assert3 = __toESM(require("assert"));
240
+ var import_node_assert2 = __toESM(require("assert"));
244
241
  var cachedFont = null;
245
242
  var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, null, function* () {
246
243
  const Jimp = yield getJimp();
@@ -346,7 +343,7 @@ var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, nu
346
343
  return image;
347
344
  });
348
345
  var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
349
- (0, import_node_assert3.default)(options.inputImgBase64, "inputImgBase64 is required");
346
+ (0, import_node_assert2.default)(options.inputImgBase64, "inputImgBase64 is required");
350
347
  let width = 0;
351
348
  let height = 0;
352
349
  let jimpImage;
@@ -396,7 +393,7 @@ var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
396
393
  });
397
394
  var processImageElementInfo = (options) => __async(void 0, null, function* () {
398
395
  const base64Image = options.inputImgBase64.split(";base64,").pop();
399
- (0, import_node_assert3.default)(base64Image, "base64Image is undefined");
396
+ (0, import_node_assert2.default)(base64Image, "base64Image is undefined");
400
397
  const [
401
398
  compositeElementInfoImgBase64,
402
399
  compositeElementInfoImgWithoutTextBase64
package/dist/es/img.d.ts CHANGED
@@ -67,11 +67,11 @@ declare function transformImgPathToBase64(inputPath: string): Promise<string>;
67
67
  * @returns A Promise that resolves to a base64-encoded string representing the resized image
68
68
  * @throws An error if the width or height cannot be determined from the metadata
69
69
  */
70
- declare function resizeImg(inputData: Buffer, newSize: {
70
+ declare function resizeImg(inputData: Buffer, newSize?: {
71
71
  width: number;
72
72
  height: number;
73
73
  }): Promise<Buffer>;
74
- declare function resizeImgBase64(inputBase64: string, newSize: {
74
+ declare function resizeImgBase64(inputData: string, newSize?: {
75
75
  width: number;
76
76
  height: number;
77
77
  }): Promise<string>;
@@ -87,7 +87,7 @@ declare function resizeImgBase64(inputBase64: string, newSize: {
87
87
  * @returns {Object} An object containing the new width and height.
88
88
  * @throws {Error} Throws an error if the width or height is not a positive number.
89
89
  */
90
- declare function zoomForGPT4o(originalWidth: number, originalHeight: number): {
90
+ declare function calculateNewDimensions(originalWidth: number, originalHeight: number): {
91
91
  width: number;
92
92
  height: number;
93
93
  };
@@ -148,4 +148,4 @@ declare function savePositionImg(options: {
148
148
  outputPath: string;
149
149
  }): Promise<void>;
150
150
 
151
- export { base64Encoded, base64ToPngFormat, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o };
151
+ export { base64Encoded, base64ToPngFormat, bufferFromBase64, calculateNewDimensions, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage };
package/dist/es/img.js CHANGED
@@ -89,7 +89,6 @@ function base64ToPngFormat(base64) {
89
89
  }
90
90
 
91
91
  // src/img/transform.ts
92
- import assert2 from "assert";
93
92
  import { Buffer as Buffer3 } from "buffer";
94
93
  function saveBase64Image(options) {
95
94
  return __async(this, null, function* () {
@@ -113,29 +112,27 @@ function resizeImg(inputData, newSize) {
113
112
  return __async(this, null, function* () {
114
113
  if (typeof inputData === "string")
115
114
  throw Error("inputData is base64, use resizeImgBase64 instead");
116
- assert2(
117
- newSize && newSize.width > 0 && newSize.height > 0,
118
- "newSize must be positive"
119
- );
120
115
  const Jimp = yield getJimp();
121
116
  const image = yield Jimp.read(inputData);
122
117
  const { width, height } = image.bitmap;
123
118
  if (!width || !height) {
124
119
  throw Error("Undefined width or height from the input image.");
125
120
  }
126
- if (newSize.width === width && newSize.height === height) {
127
- return inputData;
128
- }
129
- image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR);
121
+ const finalNewSize = newSize || calculateNewDimensions(width, height);
122
+ image.resize(
123
+ finalNewSize.width,
124
+ finalNewSize.height,
125
+ Jimp.RESIZE_NEAREST_NEIGHBOR
126
+ );
130
127
  image.quality(90);
131
128
  const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG);
132
129
  return resizedBuffer;
133
130
  });
134
131
  }
135
- function resizeImgBase64(inputBase64, newSize) {
132
+ function resizeImgBase64(inputData, newSize) {
136
133
  return __async(this, null, function* () {
137
134
  const splitFlag = ";base64,";
138
- const dataSplitted = inputBase64.split(splitFlag);
135
+ const dataSplitted = inputData.split(splitFlag);
139
136
  if (dataSplitted.length !== 2) {
140
137
  throw Error("Invalid base64 data");
141
138
  }
@@ -145,7 +142,7 @@ function resizeImgBase64(inputBase64, newSize) {
145
142
  return `${dataSplitted[0]}${splitFlag}${content}`;
146
143
  });
147
144
  }
148
- function zoomForGPT4o(originalWidth, originalHeight) {
145
+ function calculateNewDimensions(originalWidth, originalHeight) {
149
146
  const maxWidth = 2048;
150
147
  const maxHeight = 768;
151
148
  let newWidth = originalWidth;
@@ -191,7 +188,7 @@ function trimImage(image) {
191
188
  }
192
189
 
193
190
  // src/img/box-select.ts
194
- import assert3 from "assert";
191
+ import assert2 from "assert";
195
192
  var cachedFont = null;
196
193
  var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, null, function* () {
197
194
  const Jimp = yield getJimp();
@@ -297,7 +294,7 @@ var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, nu
297
294
  return image;
298
295
  });
299
296
  var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
300
- assert3(options.inputImgBase64, "inputImgBase64 is required");
297
+ assert2(options.inputImgBase64, "inputImgBase64 is required");
301
298
  let width = 0;
302
299
  let height = 0;
303
300
  let jimpImage;
@@ -347,7 +344,7 @@ var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
347
344
  });
348
345
  var processImageElementInfo = (options) => __async(void 0, null, function* () {
349
346
  const base64Image = options.inputImgBase64.split(";base64,").pop();
350
- assert3(base64Image, "base64Image is undefined");
347
+ assert2(base64Image, "base64Image is undefined");
351
348
  const [
352
349
  compositeElementInfoImgBase64,
353
350
  compositeElementInfoImgWithoutTextBase64
@@ -412,6 +409,7 @@ export {
412
409
  base64Encoded,
413
410
  base64ToPngFormat,
414
411
  bufferFromBase64,
412
+ calculateNewDimensions,
415
413
  compositeElementInfoImg,
416
414
  drawBoxOnImage,
417
415
  imageInfo,
@@ -422,6 +420,5 @@ export {
422
420
  saveBase64Image,
423
421
  savePositionImg,
424
422
  transformImgPathToBase64,
425
- trimImage,
426
- zoomForGPT4o
423
+ trimImage
427
424
  };
package/dist/lib/img.d.ts CHANGED
@@ -67,11 +67,11 @@ declare function transformImgPathToBase64(inputPath: string): Promise<string>;
67
67
  * @returns A Promise that resolves to a base64-encoded string representing the resized image
68
68
  * @throws An error if the width or height cannot be determined from the metadata
69
69
  */
70
- declare function resizeImg(inputData: Buffer, newSize: {
70
+ declare function resizeImg(inputData: Buffer, newSize?: {
71
71
  width: number;
72
72
  height: number;
73
73
  }): Promise<Buffer>;
74
- declare function resizeImgBase64(inputBase64: string, newSize: {
74
+ declare function resizeImgBase64(inputData: string, newSize?: {
75
75
  width: number;
76
76
  height: number;
77
77
  }): Promise<string>;
@@ -87,7 +87,7 @@ declare function resizeImgBase64(inputBase64: string, newSize: {
87
87
  * @returns {Object} An object containing the new width and height.
88
88
  * @throws {Error} Throws an error if the width or height is not a positive number.
89
89
  */
90
- declare function zoomForGPT4o(originalWidth: number, originalHeight: number): {
90
+ declare function calculateNewDimensions(originalWidth: number, originalHeight: number): {
91
91
  width: number;
92
92
  height: number;
93
93
  };
@@ -148,4 +148,4 @@ declare function savePositionImg(options: {
148
148
  outputPath: string;
149
149
  }): Promise<void>;
150
150
 
151
- export { base64Encoded, base64ToPngFormat, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o };
151
+ export { base64Encoded, base64ToPngFormat, bufferFromBase64, calculateNewDimensions, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage };
package/dist/lib/img.js CHANGED
@@ -54,6 +54,7 @@ __export(img_exports, {
54
54
  base64Encoded: () => base64Encoded,
55
55
  base64ToPngFormat: () => base64ToPngFormat,
56
56
  bufferFromBase64: () => bufferFromBase64,
57
+ calculateNewDimensions: () => calculateNewDimensions,
57
58
  compositeElementInfoImg: () => compositeElementInfoImg,
58
59
  drawBoxOnImage: () => drawBoxOnImage,
59
60
  imageInfo: () => imageInfo,
@@ -64,8 +65,7 @@ __export(img_exports, {
64
65
  saveBase64Image: () => saveBase64Image,
65
66
  savePositionImg: () => savePositionImg,
66
67
  transformImgPathToBase64: () => transformImgPathToBase64,
67
- trimImage: () => trimImage,
68
- zoomForGPT4o: () => zoomForGPT4o
68
+ trimImage: () => trimImage
69
69
  });
70
70
  module.exports = __toCommonJS(img_exports);
71
71
 
@@ -138,7 +138,6 @@ function base64ToPngFormat(base64) {
138
138
  }
139
139
 
140
140
  // src/img/transform.ts
141
- var import_node_assert2 = __toESM(require("assert"));
142
141
  var import_node_buffer2 = require("buffer");
143
142
  function saveBase64Image(options) {
144
143
  return __async(this, null, function* () {
@@ -162,29 +161,27 @@ function resizeImg(inputData, newSize) {
162
161
  return __async(this, null, function* () {
163
162
  if (typeof inputData === "string")
164
163
  throw Error("inputData is base64, use resizeImgBase64 instead");
165
- (0, import_node_assert2.default)(
166
- newSize && newSize.width > 0 && newSize.height > 0,
167
- "newSize must be positive"
168
- );
169
164
  const Jimp = yield getJimp();
170
165
  const image = yield Jimp.read(inputData);
171
166
  const { width, height } = image.bitmap;
172
167
  if (!width || !height) {
173
168
  throw Error("Undefined width or height from the input image.");
174
169
  }
175
- if (newSize.width === width && newSize.height === height) {
176
- return inputData;
177
- }
178
- image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR);
170
+ const finalNewSize = newSize || calculateNewDimensions(width, height);
171
+ image.resize(
172
+ finalNewSize.width,
173
+ finalNewSize.height,
174
+ Jimp.RESIZE_NEAREST_NEIGHBOR
175
+ );
179
176
  image.quality(90);
180
177
  const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG);
181
178
  return resizedBuffer;
182
179
  });
183
180
  }
184
- function resizeImgBase64(inputBase64, newSize) {
181
+ function resizeImgBase64(inputData, newSize) {
185
182
  return __async(this, null, function* () {
186
183
  const splitFlag = ";base64,";
187
- const dataSplitted = inputBase64.split(splitFlag);
184
+ const dataSplitted = inputData.split(splitFlag);
188
185
  if (dataSplitted.length !== 2) {
189
186
  throw Error("Invalid base64 data");
190
187
  }
@@ -194,7 +191,7 @@ function resizeImgBase64(inputBase64, newSize) {
194
191
  return `${dataSplitted[0]}${splitFlag}${content}`;
195
192
  });
196
193
  }
197
- function zoomForGPT4o(originalWidth, originalHeight) {
194
+ function calculateNewDimensions(originalWidth, originalHeight) {
198
195
  const maxWidth = 2048;
199
196
  const maxHeight = 768;
200
197
  let newWidth = originalWidth;
@@ -240,7 +237,7 @@ function trimImage(image) {
240
237
  }
241
238
 
242
239
  // src/img/box-select.ts
243
- var import_node_assert3 = __toESM(require("assert"));
240
+ var import_node_assert2 = __toESM(require("assert"));
244
241
  var cachedFont = null;
245
242
  var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, null, function* () {
246
243
  const Jimp = yield getJimp();
@@ -346,7 +343,7 @@ var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, nu
346
343
  return image;
347
344
  });
348
345
  var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
349
- (0, import_node_assert3.default)(options.inputImgBase64, "inputImgBase64 is required");
346
+ (0, import_node_assert2.default)(options.inputImgBase64, "inputImgBase64 is required");
350
347
  let width = 0;
351
348
  let height = 0;
352
349
  let jimpImage;
@@ -396,7 +393,7 @@ var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
396
393
  });
397
394
  var processImageElementInfo = (options) => __async(void 0, null, function* () {
398
395
  const base64Image = options.inputImgBase64.split(";base64,").pop();
399
- (0, import_node_assert3.default)(base64Image, "base64Image is undefined");
396
+ (0, import_node_assert2.default)(base64Image, "base64Image is undefined");
400
397
  const [
401
398
  compositeElementInfoImgBase64,
402
399
  compositeElementInfoImgWithoutTextBase64
@@ -462,6 +459,7 @@ function savePositionImg(options) {
462
459
  base64Encoded,
463
460
  base64ToPngFormat,
464
461
  bufferFromBase64,
462
+ calculateNewDimensions,
465
463
  compositeElementInfoImg,
466
464
  drawBoxOnImage,
467
465
  imageInfo,
@@ -472,6 +470,5 @@ function savePositionImg(options) {
472
470
  saveBase64Image,
473
471
  savePositionImg,
474
472
  transformImgPathToBase64,
475
- trimImage,
476
- zoomForGPT4o
473
+ trimImage
477
474
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "0.11.1-beta-20250214012635.0",
3
+ "version": "0.11.2",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./src/index.ts",
@@ -99,7 +99,7 @@
99
99
  "typescript": "~5.0.4",
100
100
  "@types/node": "^18.0.0",
101
101
  "rimraf": "~3.0.2",
102
- "vitest": "^1.6.0",
102
+ "vitest": "3.0.5",
103
103
  "js-sha256": "0.11.0"
104
104
  },
105
105
  "sideEffects": [],
package/src/img/index.ts CHANGED
@@ -7,10 +7,10 @@ export {
7
7
  } from './info';
8
8
  export {
9
9
  trimImage,
10
+ calculateNewDimensions,
10
11
  resizeImg,
11
12
  resizeImgBase64,
12
13
  transformImgPathToBase64,
13
- zoomForGPT4o,
14
14
  saveBase64Image,
15
15
  } from './transform';
16
16
  export { processImageElementInfo, compositeElementInfoImg } from './box-select';
@@ -1,4 +1,3 @@
1
- import assert from 'node:assert';
2
1
  import { Buffer } from 'node:buffer';
3
2
  import getJimp from './get-jimp';
4
3
 
@@ -50,7 +49,7 @@ export async function transformImgPathToBase64(inputPath: string) {
50
49
  */
51
50
  export async function resizeImg(
52
51
  inputData: Buffer,
53
- newSize: {
52
+ newSize?: {
54
53
  width: number;
55
54
  height: number;
56
55
  },
@@ -58,11 +57,6 @@ export async function resizeImg(
58
57
  if (typeof inputData === 'string')
59
58
  throw Error('inputData is base64, use resizeImgBase64 instead');
60
59
 
61
- assert(
62
- newSize && newSize.width > 0 && newSize.height > 0,
63
- 'newSize must be positive',
64
- );
65
-
66
60
  const Jimp = await getJimp();
67
61
  const image = await Jimp.read(inputData);
68
62
  const { width, height } = image.bitmap;
@@ -71,11 +65,13 @@ export async function resizeImg(
71
65
  throw Error('Undefined width or height from the input image.');
72
66
  }
73
67
 
74
- if (newSize.width === width && newSize.height === height) {
75
- return inputData;
76
- }
68
+ const finalNewSize = newSize || calculateNewDimensions(width, height);
77
69
 
78
- image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR);
70
+ image.resize(
71
+ finalNewSize.width,
72
+ finalNewSize.height,
73
+ Jimp.RESIZE_NEAREST_NEIGHBOR,
74
+ );
79
75
  image.quality(90);
80
76
  const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG);
81
77
 
@@ -83,14 +79,14 @@ export async function resizeImg(
83
79
  }
84
80
 
85
81
  export async function resizeImgBase64(
86
- inputBase64: string,
87
- newSize: {
82
+ inputData: string,
83
+ newSize?: {
88
84
  width: number;
89
85
  height: number;
90
86
  },
91
87
  ): Promise<string> {
92
88
  const splitFlag = ';base64,';
93
- const dataSplitted = inputBase64.split(splitFlag);
89
+ const dataSplitted = inputData.split(splitFlag);
94
90
  if (dataSplitted.length !== 2) {
95
91
  throw Error('Invalid base64 data');
96
92
  }
@@ -113,7 +109,10 @@ export async function resizeImgBase64(
113
109
  * @returns {Object} An object containing the new width and height.
114
110
  * @throws {Error} Throws an error if the width or height is not a positive number.
115
111
  */
116
- export function zoomForGPT4o(originalWidth: number, originalHeight: number) {
112
+ export function calculateNewDimensions(
113
+ originalWidth: number,
114
+ originalHeight: number,
115
+ ) {
117
116
  // In low mode, the image is scaled to 512x512 pixels and 85 tokens are used to represent the image.
118
117
  // In high mode, the model looks at low-resolution images and then creates detailed crop images, using 170 tokens for each 512x512 pixel tile. In practical applications, it is recommended to control the image size within 2048x768 pixels
119
118
  const maxWidth = 2048; // Maximum width