66
77class AspectRatio (str , Enum ):
88 SQUARE = "1:1 (Square)"
9+ PHOTO_V = "2:3 (Portrait Photo)"
910 PHOTO_H = "3:2 (Photo)"
11+ STANDARD_V = "3:4 (Portrait Standard)"
1012 STANDARD_H = "4:3 (Standard)"
13+ WIDESCREEN_V = "9:16 (Portrait Widescreen)"
1114 WIDESCREEN_H = "16:9 (Widescreen)"
1215 ULTRAWIDE_H = "21:9 (Ultrawide)"
13- PHOTO_V = "2:3 (Portrait Photo)"
14- STANDARD_V = "3:4 (Portrait Standard)"
15- WIDESCREEN_V = "9:16 (Portrait Widescreen)"
1616
1717
1818ASPECT_RATIOS : dict [AspectRatio , tuple [int , int ]] = {
1919 AspectRatio .SQUARE : (1 , 1 ),
20+ AspectRatio .PHOTO_V : (2 , 3 ),
2021 AspectRatio .PHOTO_H : (3 , 2 ),
22+ AspectRatio .STANDARD_V : (3 , 4 ),
2123 AspectRatio .STANDARD_H : (4 , 3 ),
24+ AspectRatio .WIDESCREEN_V : (9 , 16 ),
2225 AspectRatio .WIDESCREEN_H : (16 , 9 ),
2326 AspectRatio .ULTRAWIDE_H : (21 , 9 ),
24- AspectRatio .PHOTO_V : (2 , 3 ),
25- AspectRatio .STANDARD_V : (3 , 4 ),
26- AspectRatio .WIDESCREEN_V : (9 , 16 ),
2727}
2828
2929
@@ -50,26 +50,35 @@ def define_schema(cls):
5050 min = 0.1 ,
5151 max = 16.0 ,
5252 step = 0.1 ,
53- tooltip = "Target total megapixels. 1.0 MP ≈ 1024×1024 for square." ,
53+ tooltip = "Target total megapixels. 1.0 MP ≈ 1024x1024 for square." ,
54+ ),
55+ io .Int .Input (
56+ id = "multiple" ,
57+ default = 8 ,
58+ min = 8 ,
59+ max = 128 ,
60+ step = 4 ,
61+ tooltip = "Nearest multiple of the result to set the selected resolution to." ,
62+ advanced = True ,
5463 ),
5564 ],
5665 outputs = [
5766 io .Int .Output (
58- "width" , tooltip = "Calculated width in pixels (multiple of 8) ."
67+ "width" , tooltip = "Calculated width in pixels multiplied by the selected multiple ."
5968 ),
6069 io .Int .Output (
61- "height" , tooltip = "Calculated height in pixels (multiple of 8) ."
70+ "height" , tooltip = "Calculated height in pixels multiplied by the selected multiple ."
6271 ),
6372 ],
6473 )
6574
6675 @classmethod
67- def execute (cls , aspect_ratio : str , megapixels : float ) -> io .NodeOutput :
76+ def execute (cls , aspect_ratio : str , megapixels : float , multiple : int ) -> io .NodeOutput :
6877 w_ratio , h_ratio = ASPECT_RATIOS [aspect_ratio ]
6978 total_pixels = megapixels * 1024 * 1024
7079 scale = math .sqrt (total_pixels / (w_ratio * h_ratio ))
71- width = round (w_ratio * scale / 8 ) * 8
72- height = round (h_ratio * scale / 8 ) * 8
80+ width = round (w_ratio * scale / multiple ) * multiple
81+ height = round (h_ratio * scale / multiple ) * multiple
7382 return io .NodeOutput (width , height )
7483
7584
0 commit comments