Add aspect ratio node

This commit is contained in:
silveroxides
2026-06-15 17:30:17 +02:00
parent 5b7b2e7606
commit d77c2fa7c8
2 changed files with 26 additions and 1 deletions
+2 -1
View File
@@ -5,7 +5,7 @@ from .nodes_math import (
MathFloor, MathCeil, MathRound, MathModulo, MathAbs, MathSqrt,
MathSin, MathCos, MathTan, MathMin, MathMax, MathClamp,
MathNumberConvert, StringToNumber, NumberToString, MathCompare,
MathOperation
MathOperation, MathAspectRatio
)
from .nodes_logic import (
LogicIF, LogicAND, LogicOR, LogicNOT, LogicXOR
@@ -37,6 +37,7 @@ class LogicMathExtension(ComfyExtension):
NumberToString,
MathCompare,
MathOperation,
MathAspectRatio,
LogicIF,
LogicAND,
LogicOR,
+24
View File
@@ -542,3 +542,27 @@ class MathOperation(io.ComfyNode):
else:
res = 0
return io.NodeOutput(res)
class MathAspectRatio(io.ComfyNode):
"""Calculates the simplified aspect ratio integers from width and height."""
@classmethod
def define_schema(cls):
return io.Schema(
node_id="MathAspectRatio",
display_name="Aspect Ratio",
category="utils/math",
inputs=[
io.Int.Input("width", default=1920, min=1),
io.Int.Input("height", default=1080, min=1)
],
outputs=[
io.Int.Output(id="ratio_width", display_name="ratio_width"),
io.Int.Output(id="ratio_height", display_name="ratio_height")
],
)
@classmethod
def execute(cls, width: int, height: int) -> io.NodeOutput:
gcd = math.gcd(width, height)
return io.NodeOutput(width // gcd, height // gcd)