Skip to content

Commit 08910f2

Browse files
committed
Add Auto-Resize feature and UI fixes
Implemented automatic image resizing based on selected scaling mode (Manual/Resolution/Megapixels) with toggle option; fixed section overflow and manual scale reset.
1 parent df826fc commit 08910f2

4 files changed

Lines changed: 71 additions & 12 deletions

File tree

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,22 @@ Extensive preset library organized by use case:
137137

138138
### Auto-Detect Section
139139
- **Auto-detect Toggle**: ON/OFF switch for automatic dimension detection from connected images
140+
- Monitors input connection every second
141+
- Updates dimensions when new image is detected
142+
- Shows detected resolution in green text
140143
- **🎯 Auto-fit Button**: Finds best matching preset for current dimensions
141-
- **Auto Checkbox**: When checked, automatically applies Auto-fit when new image is detected
144+
- Analyzes both aspect ratio and total pixels
145+
- Checks both normal and flipped orientations
146+
- Applies category-specific scaling when Custom Calc is enabled
147+
- **Auto Checkbox**: Enable automatic fitting when dimensions change
148+
- Located next to Auto-Fit button
149+
- Only active when category is selected and image detected
150+
- **📐 Auto-Resize Button**: Applies scaling based on selected mode (Manual/Resolution/Megapixels)
151+
- Integrates with active scaling mode from Scaling section
152+
- Maintains manual scale value without reset to 1.0x
153+
- **Auto Checkbox**: Automatically apply scaling when new image is detected
154+
- Works in sequence after Auto-fit (if enabled)
155+
- Applies chosen scaling mode to detected dimensions
142156
- **Detected Text (green)**: Click to apply the detected image's original dimensions
143157
- **⚡ Auto-calc Button**: Applies model-specific calculations to current dimensions
144158
- **Calc Checkbox**: Enables automatic model-specific optimizations

js/ResolutionMaster.js

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ResolutionMasterCanvas {
9494
const sectionHeights = {
9595
actions: this.collapsedSections?.actions ? 25 : 55, // 25 for header, +30 for content
9696
scaling: this.collapsedSections?.scaling ? 25 : 130, // 25 for header, +105 for content
97-
autoDetect: this.collapsedSections?.autoDetect ? 25 : 90, // 25 for header, +65 for content
97+
autoDetect: this.collapsedSections?.autoDetect ? 25 : 125, // 25 for header, +100 for content (3 rows)
9898
presets: this.collapsedSections?.presets ? 25 : 55 // 25 for header, +30 for content
9999
};
100100

@@ -144,6 +144,7 @@ class ResolutionMasterCanvas {
144144
rescaleValue: 1.0,
145145
autoDetect: false,
146146
autoFitOnChange: false,
147+
autoResizeOnChange: false,
147148
selectedCategory: "Standard",
148149
selectedPreset: null,
149150
useCustomCalc: false,
@@ -340,7 +341,7 @@ class ResolutionMasterCanvas {
340341

341342
collapsibleSection("Auto-Detect", "autoDetect", (ctx, y, preview) => {
342343
if (!preview) return this.drawAutoDetectSection(ctx, y);
343-
return 65;
344+
return 100;
344345
});
345346

346347
collapsibleSection("Presets", "presets", (ctx, y, preview) => {
@@ -790,7 +791,7 @@ class ResolutionMasterCanvas {
790791
ctx.textAlign = "left";
791792
ctx.fillText("Auto", autoCheckboxX + checkboxWidth + 4, currentY + 14);
792793

793-
// Drugi rząd: Detected info (po lewej) + Auto-calc button + Calc checkbox (idealnie pod Auto-fit)
794+
// Drugi rząd: Detected info (po lewej) + Auto-Resize button + Auto checkbox
794795
currentY += 35;
795796

796797
// Klikalny napis "Detected" wycentrowany pod switchem Auto-detect
@@ -822,12 +823,27 @@ class ResolutionMasterCanvas {
822823
ctx.fillText(detectedText, textX, currentY + 14);
823824
}
824825

825-
// Auto-calc button idealnie pod Auto-fit button
826+
// Auto-Resize button pod Auto-fit button
827+
this.controls.autoResizeBtn = { x: autoFitStartX, y: currentY, w: autoFitWidth, h: 28 };
828+
this.drawButton(ctx, autoFitStartX, currentY, autoFitWidth, 28, "📐 Auto-Resize", this.hoverElement === 'autoResizeBtn');
829+
830+
// Auto-Resize checkbox pod Auto checkbox
831+
this.controls.autoResizeCheckbox = { x: autoCheckboxX, y: currentY + 5, w: checkboxWidth, h: 18 };
832+
this.drawCheckbox(ctx, autoCheckboxX, currentY + 5, checkboxWidth, props.autoResizeOnChange, this.hoverElement === 'autoResizeCheckbox');
833+
834+
ctx.fillStyle = "#ddd";
835+
ctx.font = "11px Arial";
836+
ctx.textAlign = "left";
837+
ctx.fillText("Auto", autoCheckboxX + checkboxWidth + 4, currentY + 14);
838+
839+
// Trzeci rząd: Auto-calc button + Calc checkbox
840+
currentY += 35;
841+
826842
this.controls.autoCalcBtn = { x: autoFitStartX, y: currentY, w: autoFitWidth, h: 28 };
827843
const calcEnabled = props.useCustomCalc && props.selectedCategory;
828844
this.drawButton(ctx, autoFitStartX, currentY, autoFitWidth, 28, "⚡ Auto-calc", this.hoverElement === 'autoCalcBtn', !calcEnabled);
829845

830-
// Calc checkbox idealnie pod Auto checkbox
846+
// Calc checkbox
831847
this.controls.customCalcCheckbox = { x: autoCheckboxX, y: currentY + 5, w: checkboxWidth, h: 18 };
832848
this.drawCheckbox(ctx, autoCheckboxX, currentY + 5, checkboxWidth, props.useCustomCalc, this.hoverElement === 'customCalcCheckbox');
833849

@@ -836,7 +852,7 @@ class ResolutionMasterCanvas {
836852
ctx.textAlign = "left";
837853
ctx.fillText("Calc", autoCheckboxX + checkboxWidth + 4, currentY + 14);
838854

839-
return 65;
855+
return 100;
840856
}
841857

842858
drawPresetSection(ctx, y) {
@@ -1468,6 +1484,7 @@ class ResolutionMasterCanvas {
14681484
resolutionBtn: () => this.handleResolutionScale(),
14691485
megapixelsBtn: () => this.handleMegapixelsScale(),
14701486
autoFitBtn: () => this.handleAutoFit(),
1487+
autoResizeBtn: () => this.handleAutoResize(),
14711488
autoCalcBtn: () => this.handleAutoCalc(),
14721489
detectedInfo: () => this.handleDetectedClick()
14731490
};
@@ -1490,6 +1507,8 @@ class ResolutionMasterCanvas {
14901507
const props = this.node.properties;
14911508
if (checkboxName === 'autoFitCheckbox' && props.selectedCategory) {
14921509
props.autoFitOnChange = !props.autoFitOnChange;
1510+
} else if (checkboxName === 'autoResizeCheckbox') {
1511+
props.autoResizeOnChange = !props.autoResizeOnChange;
14931512
} else if (checkboxName === 'customCalcCheckbox') {
14941513
props.useCustomCalc = !props.useCustomCalc;
14951514
}
@@ -1878,10 +1897,7 @@ class ResolutionMasterCanvas {
18781897
}
18791898

18801899
handleScale() {
1881-
this.applyScaling(
1882-
() => this.node.properties.upscaleValue,
1883-
() => { this.node.properties.upscaleValue = 1.0; }
1884-
);
1900+
this.applyScaling(() => this.node.properties.upscaleValue);
18851901
}
18861902

18871903
handleResolutionScale() {
@@ -1980,6 +1996,28 @@ class ResolutionMasterCanvas {
19801996
log.debug(`Auto-calc applied: ${currentWidth}x${currentHeight}${result.width}x${result.height} (${props.selectedCategory})`);
19811997
}
19821998

1999+
handleAutoResize() {
2000+
// Funkcja Auto-Resize - stosuje skalowanie zgodnie z zaznaczonym radio button
2001+
const props = this.node.properties;
2002+
2003+
if (!this.widthWidget || !this.heightWidget) {
2004+
log.debug("Auto-Resize: Width or height widget not found");
2005+
return;
2006+
}
2007+
2008+
// Sprawdź który tryb skalowania jest zaznaczony i zastosuj odpowiednie skalowanie
2009+
if (props.rescaleMode === 'manual') {
2010+
this.handleScale();
2011+
log.debug(`Auto-Resize: Applied manual scaling with factor ${props.upscaleValue}`);
2012+
} else if (props.rescaleMode === 'resolution') {
2013+
this.handleResolutionScale();
2014+
log.debug(`Auto-Resize: Applied resolution scaling to ${props.targetResolution}p`);
2015+
} else if (props.rescaleMode === 'megapixels') {
2016+
this.handleMegapixelsScale();
2017+
log.debug(`Auto-Resize: Applied megapixels scaling to ${props.targetMegapixels}MP`);
2018+
}
2019+
}
2020+
19832021
handleDetectedClick() {
19842022
// Funkcja obsługująca kliknięcie na napis "Detected" - nakłada oryginalne wymiary wykrytego zdjęcia
19852023
if (!this.detectedDimensions) {
@@ -2363,6 +2401,11 @@ class ResolutionMasterCanvas {
23632401
this.setDimensions(this.detectedDimensions.width, this.detectedDimensions.height);
23642402
}
23652403

2404+
// Auto-Resize: Jeśli autoResizeOnChange jest włączone, zastosuj automatyczne skalowanie
2405+
if (props.autoResizeOnChange) {
2406+
this.handleAutoResize();
2407+
}
2408+
23662409
app.graph.setDirtyCanvas(true);
23672410
}
23682411
}

js/utils/ResolutionMasterConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export const tooltips = {
2929
autoDetectToggle: "Automatically detect resolution from connected image input",
3030
autoFitBtn: "Find and apply best preset match for current resolution",
3131
autoFitCheckbox: "Automatically find and apply the best preset for the new detected image resolution",
32+
autoResizeBtn: "Apply scaling based on selected mode (Manual/Resolution/Megapixels)",
33+
autoResizeCheckbox: "Automatically apply scaling when new image is detected",
3234
detectedInfo: "Click to apply detected image resolution directly",
3335

3436
// Preset controls

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "Comfyui-Resolution-Master"
33
description = "ResolutionMaster is for total control over resolution and aspect ratio. It provides an intuitive interface with an interactive canvas, advanced scaling options, extensive presets (SDXL, Flux, WAN), and model-specific optimizations for high-quality AI image generation."
4-
version = "1.4.6"
4+
version = "1.4.7"
55
license = { text = "MIT License" }
66

77
[project.urls]

0 commit comments

Comments
 (0)