Add aspect ratio node
This commit is contained in:
+2
-1
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user