diff --git a/__init__.py b/__init__.py index d14ff0c..3ca91ce 100644 --- a/__init__.py +++ b/__init__.py @@ -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, diff --git a/nodes_math.py b/nodes_math.py index 8dd54ec..12111a5 100644 --- a/nodes_math.py +++ b/nodes_math.py @@ -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) \ No newline at end of file