Skip to content

Commit 480f15b

Browse files
author
BRADSEC
committed
Minor improvements
1 parent b764f91 commit 480f15b

7 files changed

Lines changed: 89 additions & 72 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,4 @@ Desktop.ini
122122

123123
# Claude Code files
124124
.claude/
125+
CLAUDE.md

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Resolution Selector for ComfyUI
1+
# Resolution Selector Plus for ComfyUI
22

33
Custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) providing easy resolution and empty latent selection for image generation workflows.
44

@@ -21,52 +21,54 @@ cd pathTo/ComfyUI
2121
cd custom_nodes
2222

2323
# Clone the repo into custom_nodes
24-
git clone https://github.com/bradsec/ComfyUI_ResolutionSelector.git
24+
git clone https://github.com/bradsec/ComfyUI_ResolutionSelectorPlus.git
2525

2626
# Restart ComfyUI
2727
```
2828

2929
## Usage
3030

31-
### Resolution Selector
31+
### Resolution Selector Plus
3232

33-
**Add Node:** `Add Node > utils > Resolution Selector`
33+
**Add Node:** `Add Node > utils > Resolution Selector Plus`
3434

3535
**Inputs:**
3636
- `model` (dropdown) - Select your image generation model or "All" for all resolutions
3737
- `resolution` (dropdown) - Choose from model-optimized presets with aspect ratios (e.g., "1920x1080 (16:9 Landscape)")
3838
- `resolution_multiplier` (dropdown) - Multiply preset resolution (1x, 2x, 3x, 4x)
39+
- `batch_size` (number) - Number of latent samples to generate (1-64, default: 1)
3940
- `custom_width` (optional) - Override with custom width (0-4096, step 8)
4041
- `custom_height` (optional) - Override with custom height (0-4096, step 8)
4142
- `custom_multiplier` (optional) - Independent multiplier for custom dimensions (1x, 2x, 3x, 4x)
43+
- `custom_batch` (optional) - Number of latent samples for custom resolution (1-64, default: 1)
4244

4345
**Outputs:**
4446
- `width` (INT) - Preset resolution width in pixels
4547
- `height` (INT) - Preset resolution height in pixels
46-
- `latent` (LATENT) - Empty latent tensor for preset resolution
48+
- `latent` (LATENT) - Empty latent tensor for preset resolution (batch_size samples)
4749
- `custom_width` (INT) - Custom width (0 if not set)
4850
- `custom_height` (INT) - Custom height (0 if not set)
49-
- `custom_latent` (LATENT) - Empty latent tensor for custom resolution
51+
- `custom_latent` (LATENT) - Empty latent tensor for custom resolution (custom_batch samples)
5052

5153
**Example Workflows:**
5254

5355
**Basic preset with multiplier:**
5456
```
55-
Resolution Selector (model: SDXL, resolution: "1024x1024 (1:1 Square)", multiplier: 2x)
57+
Resolution Selector Plus (model: SDXL, resolution: "1024x1024 (1:1 Square)", multiplier: 2x)
5658
→ width: 2048, height: 2048
5759
→ latent → KSampler
5860
```
5961

6062
**Custom dimensions with independent multiplier:**
6163
```
62-
Resolution Selector (custom_width: 1024, custom_height: 768, custom_multiplier: 2x)
64+
Resolution Selector Plus (custom_width: 1024, custom_height: 768, custom_multiplier: 2x)
6365
→ custom_width: 2048, custom_height: 1536
6466
→ custom_latent → KSampler
6567
```
6668

6769
**Using "All" model option:**
6870
```
69-
Resolution Selector (model: All, resolution: "1920x1080 (16:9 Landscape)")
70-
→ Shows all 34 unique resolutions from all models
71+
Resolution Selector Plus (model: All, resolution: "1920x1080 (16:9 Landscape)")
72+
→ Shows all 74 unique resolutions from all models
7173
```
7274

node_preview.png

5.49 KB
Loading

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[project]
22
name = "comfyui_resolutionselectorplus"
33
description = "Custom node for ComfyUI providing easy resolution and empty latent selection for image generation workflows."
4-
version = "2.0.4"
4+
version = "2.0.5"
55
license = {file = "LICENSE"}
66

77
[project.urls]
8-
Repository = "https://github.com/bradsec/ComfyUI_ResolutionSelector"
8+
Repository = "https://github.com/bradsec/ComfyUI_ResolutionSelectorPlus"
99
# Used by Comfy Registry https://comfyregistry.org
1010

1111
[tool.comfy]

resolution_selector.py

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,36 @@
88

99

1010
# Model-specific resolution presets with constraints
11+
# Includes: model-optimized sizes + photo print (4x6, 5x7, 8x10) + digital/social + canvas art ratios
1112
MODEL_RESOLUTIONS = {
1213
"Flux": {
13-
"square": [(512, 512), (768, 768), (1024, 1024), (1280, 1280), (1536, 1536), (1920, 1920), (2048, 2048)],
14-
"portrait": [(768, 1344), (832, 1216), (896, 1152), (928, 1664), (1024, 1536), (1024, 1792), (1080, 1920), (1152, 2048)],
15-
"landscape": [(1344, 768), (1216, 832), (1152, 896), (1536, 1024), (1664, 928), (1792, 1024), (1920, 1080), (2048, 1152)],
14+
"square": [(512, 512), (768, 768), (1024, 1024), (1088, 1088), (1280, 1280), (1536, 1536), (1920, 1920), (2048, 2048)],
15+
"portrait": [(688, 2048), (768, 1344), (832, 1216), (896, 1152), (928, 1664), (1024, 1536), (1024, 1792), (1024, 2048), (1088, 1920), (1152, 2048), (1200, 1792), (1360, 2048), (1456, 2048), (1536, 2048), (1616, 2048), (1632, 2048), (1712, 2048)],
16+
"landscape": [(1280, 720), (1344, 768), (1216, 832), (1152, 896), (1536, 1024), (1664, 928), (1792, 1024), (1792, 1200), (1920, 1088), (2048, 688), (2048, 1024), (2048, 1152), (2048, 1360), (2048, 1456), (2048, 1536), (2048, 1616), (2048, 1632), (2048, 1712)],
1617
"constraints": {"divisible_by": 16, "min": 256, "max": 2048}
1718
},
1819
"Qwen Image": {
19-
"square": [(1024, 1024), (1280, 1280), (1328, 1328), (1536, 1536), (1920, 1920), (2048, 2048)],
20-
"portrait": [(928, 1664), (1024, 1536), (1080, 1920), (1140, 1472), (1152, 2048)],
21-
"landscape": [(1472, 1140), (1536, 1024), (1664, 928), (1920, 1080), (2048, 1152)],
20+
"square": [(1024, 1024), (1080, 1080), (1280, 1280), (1328, 1328), (1536, 1536), (1920, 1920), (2048, 2048)],
21+
"portrait": [(680, 2048), (928, 1664), (1024, 1536), (1024, 2048), (1080, 1920), (1140, 1472), (1152, 2048), (1200, 1800), (1368, 2048), (1464, 2048), (1536, 2048), (1608, 2048), (1640, 2048), (1704, 2048)],
22+
"landscape": [(1280, 720), (1472, 1140), (1536, 1024), (1664, 928), (1800, 1200), (1920, 1080), (2048, 680), (2048, 1024), (2048, 1152), (2048, 1368), (2048, 1464), (2048, 1536), (2048, 1608), (2048, 1640), (2048, 1704)],
2223
"constraints": {"divisible_by": 8, "min": 256, "max": 2048}
2324
},
2425
"Z-Image": {
25-
"square": [(512, 512), (768, 768), (1024, 1024), (1280, 1280), (1536, 1536), (1920, 1920), (2048, 2048)],
26-
"portrait": [(720, 1280), (768, 1024), (1080, 1920), (1152, 2048)],
27-
"landscape": [(1024, 768), (1280, 720), (1920, 1080), (2048, 1152)],
26+
"square": [(512, 512), (768, 768), (1024, 1024), (1080, 1080), (1280, 1280), (1536, 1536), (1920, 1920), (2048, 2048)],
27+
"portrait": [(680, 2048), (720, 1280), (768, 1024), (1024, 2048), (1080, 1920), (1152, 2048), (1200, 1800), (1368, 2048), (1464, 2048), (1536, 2048), (1608, 2048), (1640, 2048), (1704, 2048)],
28+
"landscape": [(1024, 768), (1280, 720), (1800, 1200), (1920, 1080), (2048, 680), (2048, 1024), (2048, 1152), (2048, 1368), (2048, 1464), (2048, 1536), (2048, 1608), (2048, 1640), (2048, 1704)],
2829
"constraints": {"divisible_by": 8, "min": 256, "max": 2048}
2930
},
3031
"SD 1.5": {
31-
"square": [(512, 512), (768, 768), (1024, 1024), (1280, 1280), (1536, 1536)],
32-
"portrait": [(512, 768), (512, 682), (512, 1024), (768, 1024), (768, 1344), (1080, 1920)],
33-
"landscape": [(768, 512), (1024, 512), (1024, 768), (1344, 768), (1536, 512), (1920, 1080)],
32+
"square": [(512, 512), (768, 768), (1024, 1024), (1080, 1080), (1280, 1280), (1536, 1536)],
33+
"portrait": [(512, 768), (512, 682), (512, 1024), (680, 2048), (768, 1024), (768, 1344), (1024, 2048), (1080, 1920), (1200, 1800), (1368, 2048), (1464, 2048), (1536, 2048), (1608, 2048), (1640, 2048), (1704, 2048)],
34+
"landscape": [(768, 512), (1024, 512), (1024, 768), (1280, 720), (1344, 768), (1536, 512), (1800, 1200), (1920, 1080), (2048, 680), (2048, 1024), (2048, 1368), (2048, 1464), (2048, 1536), (2048, 1608), (2048, 1640), (2048, 1704)],
3435
"constraints": {"divisible_by": 8, "min": 256, "max": 2048}
3536
},
3637
"SDXL": {
37-
"square": [(1024, 1024), (1280, 1280), (1536, 1536), (1920, 1920), (2048, 2048)],
38-
"portrait": [(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1536), (1080, 1920), (1152, 2048)],
39-
"landscape": [(1152, 896), (1216, 832), (1344, 768), (1536, 640), (1536, 1024), (1920, 1080), (2048, 1152)],
38+
"square": [(1024, 1024), (1080, 1080), (1280, 1280), (1536, 1536), (1920, 1920), (2048, 2048)],
39+
"portrait": [(640, 1536), (680, 2048), (768, 1344), (832, 1216), (896, 1152), (1024, 1536), (1024, 2048), (1080, 1920), (1152, 2048), (1200, 1800), (1368, 2048), (1464, 2048), (1536, 2048), (1608, 2048), (1640, 2048), (1704, 2048)],
40+
"landscape": [(1152, 896), (1216, 832), (1280, 720), (1344, 768), (1536, 640), (1536, 1024), (1800, 1200), (1920, 1080), (2048, 680), (2048, 1024), (2048, 1152), (2048, 1368), (2048, 1464), (2048, 1536), (2048, 1608), (2048, 1640), (2048, 1704)],
4041
"constraints": {"divisible_by": 8, "min": 256, "max": 2048}
4142
}
4243
}
@@ -60,7 +61,7 @@ def gcd(a, b):
6061

6162
def calculate_aspect_ratio(width, height):
6263
"""
63-
Calculate simplified aspect ratio from dimensions, rounding to common ratios.
64+
Calculate simplified aspect ratio from dimensions, using nearest common ratio.
6465
6566
Args:
6667
width (int): Width in pixels
@@ -91,19 +92,12 @@ def calculate_aspect_ratio(width, height):
9192
(0.56, "9:16"), # 0.5625
9293
(0.5, "1:2"), # 0.5
9394
(0.42, "5:12"), # 0.4166...
95+
(0.33, "1:3"), # 0.333... (panoramic)
9496
]
9597

96-
# Find closest common ratio (within 5% tolerance)
97-
tolerance = 0.05
98-
for ratio_value, ratio_str in common_ratios:
99-
if abs(actual_ratio - ratio_value) / ratio_value < tolerance:
100-
return ratio_str
101-
102-
# If no close match, calculate GCD-based ratio
103-
divisor = gcd(width, height)
104-
ratio_width = width // divisor
105-
ratio_height = height // divisor
106-
return f"{ratio_width}:{ratio_height}"
98+
# Find closest common ratio by absolute difference
99+
closest_ratio = min(common_ratios, key=lambda r: abs(actual_ratio - r[0]))
100+
return closest_ratio[1]
107101

108102

109103
def format_resolution(width, height):
@@ -283,6 +277,13 @@ def INPUT_TYPES(cls):
283277
"resolution_multiplier": (["1x", "2x", "3x", "4x"], {
284278
"default": "1x"
285279
}),
280+
"batch_size": ("INT", {
281+
"default": 1,
282+
"min": 1,
283+
"max": 64,
284+
"step": 1,
285+
"display": "number"
286+
}),
286287
},
287288
"optional": {
288289
"custom_width": ("INT", {
@@ -302,6 +303,13 @@ def INPUT_TYPES(cls):
302303
"custom_multiplier": (["1x", "2x", "3x", "4x"], {
303304
"default": "1x"
304305
}),
306+
"custom_batch": ("INT", {
307+
"default": 1,
308+
"min": 1,
309+
"max": 64,
310+
"step": 1,
311+
"display": "number"
312+
}),
305313
}
306314
}
307315

@@ -310,17 +318,19 @@ def INPUT_TYPES(cls):
310318
FUNCTION = "select_resolution"
311319
CATEGORY = "utils"
312320

313-
def select_resolution(self, model, resolution, resolution_multiplier="1x", custom_width=0, custom_height=0, custom_multiplier="1x"):
321+
def select_resolution(self, model, resolution, resolution_multiplier="1x", batch_size=1, custom_width=0, custom_height=0, custom_multiplier="1x", custom_batch=1):
314322
"""
315323
Select and validate resolution, generate outputs.
316324
317325
Args:
318326
model (str): Selected model name
319327
resolution (str): Selected preset resolution string
320328
resolution_multiplier (str): Multiplier for resolution (1x-4x)
329+
batch_size (int): Number of latent samples for preset resolution (default: 1)
321330
custom_width (int, optional): Custom width override
322331
custom_height (int, optional): Custom height override
323332
custom_multiplier (str, optional): Multiplier for custom dimensions (1x-4x)
333+
custom_batch (int, optional): Number of latent samples for custom resolution (default: 1)
324334
325335
Returns:
326336
tuple: (width: int, height: int, latent: dict, custom_width: int, custom_height: int, custom_latent: dict)
@@ -336,8 +346,8 @@ def select_resolution(self, model, resolution, resolution_multiplier="1x", custo
336346
width *= multiplier
337347
height *= multiplier
338348

339-
# Generate latent for preset resolution
340-
latent = self._generate_empty_latent(width, height)
349+
# Generate latent for preset resolution with batch size
350+
latent = self._generate_empty_latent(width, height, batch_size)
341351

342352
# Determine final custom dimensions
343353
if custom_width > 0 and custom_height > 0:
@@ -349,13 +359,13 @@ def select_resolution(self, model, resolution, resolution_multiplier="1x", custo
349359
if model != "All":
350360
self._validate_dimensions(model, final_custom_width, final_custom_height)
351361

352-
# Generate custom latent
353-
custom_latent = self._generate_empty_latent(final_custom_width, final_custom_height)
362+
# Generate custom latent with custom batch size
363+
custom_latent = self._generate_empty_latent(final_custom_width, final_custom_height, custom_batch)
354364

355365
return (width, height, latent, final_custom_width, final_custom_height, custom_latent)
356366
else:
357367
# No custom dimensions, return zeros and minimal empty custom latent
358-
custom_latent = self._generate_empty_latent(1, 1)
368+
custom_latent = self._generate_empty_latent(1, 1, 1)
359369

360370
return (width, height, latent, 0, 0, custom_latent)
361371

@@ -433,5 +443,5 @@ def _generate_empty_latent(self, width, height, batch_size=1):
433443
}
434444

435445
NODE_DISPLAY_NAME_MAPPINGS = {
436-
"ResolutionSelector": "Resolution Selector",
446+
"ResolutionSelector": "Resolution Selector Plus",
437447
}

test_resolution_selector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def test_model_resolutions():
8585
flux_res = get_resolution_list("Flux")
8686
print(f" Flux has {len(flux_res)} resolutions")
8787
assert len(flux_res) > 0, "Flux should have resolutions"
88-
assert any("1920x1080" in r for r in flux_res), "Flux should have 1920x1080"
88+
# Flux uses 16-pixel divisibility, so 1920x1080 becomes 1920x1088
89+
assert any("1920x1088" in r for r in flux_res), "Flux should have 1920x1088 (Full HD adapted to 16px divisibility)"
8990

9091
# Test All model
9192
all_res = get_resolution_list("All")

web/js/resolution_selector.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
import { app } from "/scripts/app.js";
22

3+
// Model-specific resolution presets with constraints
4+
// Includes: model-optimized sizes + photo print (4x6, 5x7, 8x10) + digital/social + canvas art ratios
35
const MODEL_RESOLUTIONS = {
46
"Flux": {
5-
"square": [[512, 512], [768, 768], [1024, 1024], [1280, 1280], [1536, 1536], [1920, 1920], [2048, 2048]],
6-
"portrait": [[768, 1344], [832, 1216], [896, 1152], [928, 1664], [1024, 1536], [1024, 1792], [1080, 1920], [1152, 2048]],
7-
"landscape": [[1344, 768], [1216, 832], [1152, 896], [1536, 1024], [1664, 928], [1792, 1024], [1920, 1080], [2048, 1152]],
7+
"square": [[512, 512], [768, 768], [1024, 1024], [1088, 1088], [1280, 1280], [1536, 1536], [1920, 1920], [2048, 2048]],
8+
"portrait": [[688, 2048], [768, 1344], [832, 1216], [896, 1152], [928, 1664], [1024, 1536], [1024, 1792], [1024, 2048], [1088, 1920], [1152, 2048], [1200, 1792], [1360, 2048], [1456, 2048], [1536, 2048], [1616, 2048], [1632, 2048], [1712, 2048]],
9+
"landscape": [[1280, 720], [1344, 768], [1216, 832], [1152, 896], [1536, 1024], [1664, 928], [1792, 1024], [1792, 1200], [1920, 1088], [2048, 688], [2048, 1024], [2048, 1152], [2048, 1360], [2048, 1456], [2048, 1536], [2048, 1616], [2048, 1632], [2048, 1712]],
810
},
911
"Qwen Image": {
10-
"square": [[1024, 1024], [1280, 1280], [1328, 1328], [1536, 1536], [1920, 1920], [2048, 2048]],
11-
"portrait": [[928, 1664], [1024, 1536], [1080, 1920], [1140, 1472], [1152, 2048]],
12-
"landscape": [[1472, 1140], [1536, 1024], [1664, 928], [1920, 1080], [2048, 1152]],
12+
"square": [[1024, 1024], [1080, 1080], [1280, 1280], [1328, 1328], [1536, 1536], [1920, 1920], [2048, 2048]],
13+
"portrait": [[680, 2048], [928, 1664], [1024, 1536], [1024, 2048], [1080, 1920], [1140, 1472], [1152, 2048], [1200, 1800], [1368, 2048], [1464, 2048], [1536, 2048], [1608, 2048], [1640, 2048], [1704, 2048]],
14+
"landscape": [[1280, 720], [1472, 1140], [1536, 1024], [1664, 928], [1800, 1200], [1920, 1080], [2048, 680], [2048, 1024], [2048, 1152], [2048, 1368], [2048, 1464], [2048, 1536], [2048, 1608], [2048, 1640], [2048, 1704]],
1315
},
1416
"Z-Image": {
15-
"square": [[512, 512], [768, 768], [1024, 1024], [1280, 1280], [1536, 1536], [1920, 1920], [2048, 2048]],
16-
"portrait": [[720, 1280], [768, 1024], [1080, 1920], [1152, 2048]],
17-
"landscape": [[1024, 768], [1280, 720], [1920, 1080], [2048, 1152]],
17+
"square": [[512, 512], [768, 768], [1024, 1024], [1080, 1080], [1280, 1280], [1536, 1536], [1920, 1920], [2048, 2048]],
18+
"portrait": [[680, 2048], [720, 1280], [768, 1024], [1024, 2048], [1080, 1920], [1152, 2048], [1200, 1800], [1368, 2048], [1464, 2048], [1536, 2048], [1608, 2048], [1640, 2048], [1704, 2048]],
19+
"landscape": [[1024, 768], [1280, 720], [1800, 1200], [1920, 1080], [2048, 680], [2048, 1024], [2048, 1152], [2048, 1368], [2048, 1464], [2048, 1536], [2048, 1608], [2048, 1640], [2048, 1704]],
1820
},
1921
"SD 1.5": {
20-
"square": [[512, 512], [768, 768], [1024, 1024], [1280, 1280], [1536, 1536]],
21-
"portrait": [[512, 768], [512, 682], [512, 1024], [768, 1024], [768, 1344], [1080, 1920]],
22-
"landscape": [[768, 512], [1024, 512], [1024, 768], [1344, 768], [1536, 512], [1920, 1080]],
22+
"square": [[512, 512], [768, 768], [1024, 1024], [1080, 1080], [1280, 1280], [1536, 1536]],
23+
"portrait": [[512, 768], [512, 682], [512, 1024], [680, 2048], [768, 1024], [768, 1344], [1024, 2048], [1080, 1920], [1200, 1800], [1368, 2048], [1464, 2048], [1536, 2048], [1608, 2048], [1640, 2048], [1704, 2048]],
24+
"landscape": [[768, 512], [1024, 512], [1024, 768], [1280, 720], [1344, 768], [1536, 512], [1800, 1200], [1920, 1080], [2048, 680], [2048, 1024], [2048, 1368], [2048, 1464], [2048, 1536], [2048, 1608], [2048, 1640], [2048, 1704]],
2325
},
2426
"SDXL": {
25-
"square": [[1024, 1024], [1280, 1280], [1536, 1536], [1920, 1920], [2048, 2048]],
26-
"portrait": [[640, 1536], [768, 1344], [832, 1216], [896, 1152], [1024, 1536], [1080, 1920], [1152, 2048]],
27-
"landscape": [[1152, 896], [1216, 832], [1344, 768], [1536, 640], [1536, 1024], [1920, 1080], [2048, 1152]],
27+
"square": [[1024, 1024], [1080, 1080], [1280, 1280], [1536, 1536], [1920, 1920], [2048, 2048]],
28+
"portrait": [[640, 1536], [680, 2048], [768, 1344], [832, 1216], [896, 1152], [1024, 1536], [1024, 2048], [1080, 1920], [1152, 2048], [1200, 1800], [1368, 2048], [1464, 2048], [1536, 2048], [1608, 2048], [1640, 2048], [1704, 2048]],
29+
"landscape": [[1152, 896], [1216, 832], [1280, 720], [1344, 768], [1536, 640], [1536, 1024], [1800, 1200], [1920, 1080], [2048, 680], [2048, 1024], [2048, 1152], [2048, 1368], [2048, 1464], [2048, 1536], [2048, 1608], [2048, 1640], [2048, 1704]],
2830
}
2931
};
3032

@@ -60,21 +62,22 @@ function calculateAspectRatio(width, height) {
6062
[0.56, "9:16"], // 0.5625
6163
[0.5, "1:2"], // 0.5
6264
[0.42, "5:12"], // 0.4166...
65+
[0.33, "1:3"], // 0.333... (panoramic)
6366
];
6467

65-
// Find closest common ratio (within 5% tolerance)
66-
const tolerance = 0.05;
67-
for (const [ratioValue, ratioStr] of commonRatios) {
68-
if (Math.abs(actualRatio - ratioValue) / ratioValue < tolerance) {
69-
return ratioStr;
68+
// Find closest common ratio by absolute difference
69+
let closestRatio = commonRatios[0];
70+
let minDiff = Math.abs(actualRatio - closestRatio[0]);
71+
72+
for (const ratio of commonRatios) {
73+
const diff = Math.abs(actualRatio - ratio[0]);
74+
if (diff < minDiff) {
75+
minDiff = diff;
76+
closestRatio = ratio;
7077
}
7178
}
7279

73-
// If no close match, calculate GCD-based ratio
74-
const divisor = gcd(width, height);
75-
const ratioWidth = width / divisor;
76-
const ratioHeight = height / divisor;
77-
return `${ratioWidth}:${ratioHeight}`;
80+
return closestRatio[1];
7881
}
7982

8083
function formatResolution(width, height) {

0 commit comments

Comments
 (0)