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