Skip to content

Commit 2fa16ef

Browse files
committed
Update calculation and wording to provide better understanding
1 parent eeb62fd commit 2fa16ef

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/App.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ function App() {
201201
The calculation involves several steps:
202202
</Typography>
203203
<Typography paragraph>
204-
1. <b>Resizing Images</b>: Each image is resized to a
205-
minimum size while maintaining its aspect ratio. The minimum
206-
size is {model.imageMinSizeLength}px.
204+
1. <b>Resizing Images</b>: Ensure each image is resized to
205+
fit within the maximum dimension {model.maxImageDimension}
206+
px, and has at least {model.imageMinSizeLength}px on the
207+
shortest side, while maintaining its aspect ratio.
207208
</Typography>
208209
<Typography paragraph>
209210
2. <b>Calculating Tiles</b>: The resized image is divided

src/stores/CalcStore.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,25 @@ export const calcStore = (set, get) => ({
2121
set(() => ({ totalTokens: null, totalCost: null }));
2222
},
2323
runCalculation: () => {
24-
function getResizedImageSize(minSize, height, width) {
24+
function getResizedImageSize(maxDimension, minSide, height, width) {
2525
let resizedHeight = height;
2626
let resizedWidth = width;
2727

28-
if (height > width) {
29-
resizedHeight = minSize;
30-
} else {
31-
resizedHeight = (height / width) * minSize;
28+
// Only scale down if larger than maxDimension on any side
29+
if (width > maxDimension || height > maxDimension) {
30+
const scaleFactor = Math.min(
31+
maxDimension / width,
32+
maxDimension / height
33+
);
34+
resizedWidth = width * scaleFactor;
35+
resizedHeight = height * scaleFactor;
3236
}
3337

34-
if (height > width) {
35-
resizedWidth = (width / height) * minSize;
36-
} else {
37-
resizedWidth = minSize;
38+
// If the shortest side is greater than minSide, scale to minSide
39+
if (Math.min(resizedWidth, resizedHeight) > minSide) {
40+
const scaleFactor = minSide / Math.min(resizedWidth, resizedHeight);
41+
resizedWidth = resizedWidth * scaleFactor;
42+
resizedHeight = resizedHeight * scaleFactor;
3843
}
3944

4045
return { height: resizedHeight, width: resizedWidth };
@@ -48,13 +53,15 @@ export const calcStore = (set, get) => ({
4853

4954
const { model, images } = get();
5055
const tokensPerTile = model.tokensPerTile;
56+
const maxImageDimension = model.maxImageDimension;
5157
const imageMinSizeLength = model.imageMinSizeLength;
5258
const tileSizeLength = model.tileSizeLength;
5359
const additionalBuffer = model.additionalBuffer;
5460
const costPerThousandTokens = model.costPerThousandTokens;
5561

5662
const imageTileCount = images.flatMap((image) => {
5763
const imgSize = getResizedImageSize(
64+
maxImageDimension,
5865
imageMinSizeLength,
5966
image.height,
6067
image.width

src/stores/ModelStore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const modelStore = (set, get) => ({
33
{
44
name: "GPT-4o (2024-08-06 - Standard)",
55
tokensPerTile: 170,
6+
maxImageDimension: 2048,
67
imageMinSizeLength: 768,
78
tileSizeLength: 512,
89
additionalBuffer: 85,
@@ -11,6 +12,7 @@ export const modelStore = (set, get) => ({
1112
{
1213
name: "GPT-4o (2024-08-06 - Global)",
1314
tokensPerTile: 170,
15+
maxImageDimension: 2048,
1416
imageMinSizeLength: 768,
1517
tileSizeLength: 512,
1618
additionalBuffer: 85,
@@ -19,6 +21,7 @@ export const modelStore = (set, get) => ({
1921
{
2022
name: "GPT-4o-mini (2024-07-18)",
2123
tokensPerTile: 5667,
24+
maxImageDimension: 2048,
2225
imageMinSizeLength: 768,
2326
tileSizeLength: 512,
2427
additionalBuffer: 2833,
@@ -27,6 +30,7 @@ export const modelStore = (set, get) => ({
2730
{
2831
name: "GPT-4o (2024-05-13)",
2932
tokensPerTile: 170,
33+
maxImageDimension: 2048,
3034
imageMinSizeLength: 768,
3135
tileSizeLength: 512,
3236
additionalBuffer: 85,

0 commit comments

Comments
 (0)