Delete ComfyUI_Resolution-and-Ratio directory

This commit is contained in:
SamLiu1000
2025-12-31 17:30:49 +08:00
committed by GitHub
parent e9ac677e63
commit f2e7286b32
3 changed files with 0 additions and 240 deletions
-12
View File
@@ -1,12 +0,0 @@
from .resolution_and_ratio import ResolutionAndRatio
NODE_CLASS_MAPPINGS = {
"ResolutionAndRatio": ResolutionAndRatio
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ResolutionAndRatio": "Resolution and Ratio"
}
WEB_DIRECTORY = "./web"
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', 'WEB_DIRECTORY']
@@ -1,61 +0,0 @@
import math
class ResolutionAndRatio:
@classmethod
def INPUT_TYPES(cls):
default_presets = (
"128x128\n256x256\n512x512\n512x768\n768x768\n1024x1024\n896x1216\n1216x896\n"
"1088x1920\n1920x1088\n1152x1536\n1536x1152\n1536x2048\n2048x1536\n2048x2048"
)
return {
"required": {
"width": ("INT", {"default": 1152, "min": 64, "max": 4096, "step": 32}),
"height": ("INT", {"default": 1536, "min": 64, "max": 4096, "step": 32}),
"W_ratio": ("INT", {"default": 3, "min": 1, "max": 100}),
"H_ratio": ("INT", {"default": 4, "min": 1, "max": 100}),
"scale_percent": ("INT", {"default": 100, "min": 10, "max": 200, "step": 5, "display": "slider"}),
"reset": ("BOOLEAN", {"default": False, "label_on": "RESET", "label_off": "RESET"}),
"swap": ("BOOLEAN", {"default": False, "label_on": "SWAP", "label_off": "SWAP"}),
"preset": (["Custom"],),
"custom_presets": ("STRING", {"multiline": True, "default": default_presets}),
},
}
RETURN_TYPES = ("INT", "INT")
RETURN_NAMES = ("width", "height")
FUNCTION = "get_resolution"
CATEGORY = "CustomUtils"
def get_resolution(self, width, height, W_ratio, H_ratio, scale_percent, reset, swap, preset, custom_presets):
# Handle reset (mainly handled by JS, but included for completeness)
if reset:
width = 256
height = 256
# Handle swap
if swap:
width, height = height, width
W_ratio, H_ratio = H_ratio, W_ratio
# Round to nearest multiple of 32
width = round(width / 32) * 32
height = round(height / 32) * 32
# Ensure minimum values
width = max(64, width)
height = max(64, height)
# Ensure maximum values
width = min(4096, width)
height = min(4096, height)
return (width, height)
@classmethod
def VALIDATE_INPUTS(cls, width, height, **kwargs):
if width < 64 or height < 64:
return "Width and height must be at least 64"
if width > 4096 or height > 4096:
return "Width and height must not exceed 4096"
return True
@@ -1,167 +0,0 @@
import { app } from "../../scripts/app.js";
app.registerExtension({
name: "Comfy.ResolutionAndRatio",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "ResolutionAndRatio") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
onNodeCreated?.apply(this, arguments);
const getWidget = (name) => this.widgets.find(w => w.name === name);
const wWidget = getWidget("width");
const hWidget = getWidget("height");
const rwWidget = getWidget("W_ratio");
const rhWidget = getWidget("H_ratio");
const scalePercentWidget = getWidget("scale_percent");
const resetWidget = getWidget("reset");
const swapWidget = getWidget("swap");
const presetWidget = getWidget("preset");
const customWidget = getWidget("custom_presets");
// Store base resolution for scale calculations
let baseWidth = wWidget.value;
let baseHeight = hWidget.value;
// Helper function to round to nearest multiple of 32
const roundTo32 = (val) => Math.round(val / 32) * 32;
// Helper function to clamp value between min and max
const clamp = (val, min, max) => Math.max(min, Math.min(max, val));
// Update base resolution when width/height changes manually
const originalWCallback = wWidget.callback;
wWidget.callback = function() {
baseWidth = wWidget.value;
// Update scale to match current resolution
const currentScale = Math.round((wWidget.value / baseWidth) * 100);
if (currentScale >= 10 && currentScale <= 200) {
scalePercentWidget.value = currentScale;
}
if (originalWCallback) originalWCallback.apply(this, arguments);
};
const originalHCallback = hWidget.callback;
hWidget.callback = function() {
baseHeight = hWidget.value;
// Update scale to match current resolution
const currentScale = Math.round((hWidget.value / baseHeight) * 100);
if (currentScale >= 10 && currentScale <= 200) {
scalePercentWidget.value = currentScale;
}
if (originalHCallback) originalHCallback.apply(this, arguments);
};
// Scale slider updates resolution in real-time
scalePercentWidget.callback = () => {
const newWidth = roundTo32(baseWidth * scalePercentWidget.value / 100);
const newHeight = roundTo32(baseHeight * scalePercentWidget.value / 100);
wWidget.value = clamp(newWidth, 64, 4096);
hWidget.value = clamp(newHeight, 64, 4096);
};
// Ratio synchronization with 4096 limit
rwWidget.callback = () => {
const newWidth = roundTo32((hWidget.value / rhWidget.value) * rwWidget.value);
const clampedWidth = clamp(newWidth, 64, 4096);
// If hitting limit, prevent ratio from increasing further
if (newWidth > 4096) {
// Calculate max ratio that keeps width at 4096
const maxRatio = Math.floor((4096 * rhWidget.value) / hWidget.value);
rwWidget.value = maxRatio;
wWidget.value = 4096;
} else {
wWidget.value = clampedWidth;
}
// Update base and scale
baseWidth = wWidget.value;
scalePercentWidget.value = 100;
};
rhWidget.callback = () => {
const newHeight = roundTo32((wWidget.value / rwWidget.value) * rhWidget.value);
const clampedHeight = clamp(newHeight, 64, 4096);
// If hitting limit, prevent ratio from increasing further
if (newHeight > 4096) {
// Calculate max ratio that keeps height at 4096
const maxRatio = Math.floor((4096 * rwWidget.value) / wWidget.value);
rhWidget.value = maxRatio;
hWidget.value = 4096;
} else {
hWidget.value = clampedHeight;
}
// Update base and scale
baseHeight = hWidget.value;
scalePercentWidget.value = 100;
};
// RESET logic
resetWidget.callback = () => {
wWidget.value = 256;
hWidget.value = 256;
rwWidget.value = 1;
rhWidget.value = 1;
scalePercentWidget.value = 100;
baseWidth = 256;
baseHeight = 256;
// Reset button after a short delay
setTimeout(() => { resetWidget.value = false; }, 200);
};
// SWAP logic
swapWidget.callback = () => {
const tempV = wWidget.value;
wWidget.value = hWidget.value;
hWidget.value = tempV;
const tempR = rwWidget.value;
rwWidget.value = rhWidget.value;
rhWidget.value = tempR;
const tempBase = baseWidth;
baseWidth = baseHeight;
baseHeight = tempBase;
// Reset swap button after a short delay
setTimeout(() => { swapWidget.value = false; }, 200);
};
// Update preset dropdown from custom presets
const updatePresets = () => {
const lines = customWidget.value.split('\n')
.map(l => l.trim())
.filter(l => l.toLowerCase().includes('x'));
presetWidget.options.values = ["Custom", ...lines];
};
customWidget.callback = updatePresets;
setTimeout(updatePresets, 100);
// Apply selected preset
presetWidget.callback = (v) => {
if (v !== "Custom") {
const parts = v.toLowerCase().split('x');
if (parts.length === 2) {
const w = parseInt(parts[0]);
const h = parseInt(parts[1]);
if (!isNaN(w) && !isNaN(h)) {
wWidget.value = clamp(w, 64, 4096);
hWidget.value = clamp(h, 64, 4096);
baseWidth = wWidget.value;
baseHeight = hWidget.value;
scalePercentWidget.value = 100;
}
}
}
};
};
}
}
});