ComfyUI Extension: AspectRatioAdvanced
An advanced aspect ratio calculator and image scaler with flexible scaling modes and intelligent image handling.
Custom Nodes (0)
README
AspectRatioAdvanced - ComfyUI Node
An advanced aspect ratio calculator and image scaler for ComfyUI with flexible scaling modes and intelligent image handling.
<img width="399" height="604" alt="image" src="https://github.com/user-attachments/assets/8351df62-0a5e-479a-99c2-ff57d4e752f8" />Features
š Flexible Scaling
- Aspect Ratio: Choose an aspect ratio to be calculated from target megapixels, min/max side, or input image.
- Custom dimensions: Scale to custom width and height
- Target Megapixels: Scale to achieve a specific resolution
- Min Side: Set shortest dimension, maintain aspect ratio
- Max Side: Set longest dimension, maintain aspect ratio
- 12 preset aspect ratios: square, portrait, landscape, and social media formats
š¼ļø Intelligent Image Processing
- Optional image input automatically detects aspect ratio when
use_image_ratio
is set toYes
. - Real-time image scaling to calculated dimensions
ā” Advanced Controls
- Dimension flipping (portrait ā landscape)
- Batch processing support
- 8-divisible dimensions (latent space compatible)
Installation
1. Via ComfyUI Manager
- Open ComfyUI Manager ā Custom Nodes
- Search for Aspect Ratio Advanced.
- Press Install and restart ComfyUI.
2. Manually by clone or copy.
- Navigate to your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes/
- Clone or copy this repository:
git clone https://github.com/Dehypnotic/comfyui-aspect-ratio-advanced.git
- Restart ComfyUI
Usage
Basic Aspect Ratio Calculation
- Select desired
aspect_ratio
preset - Choose
scaling_mode
(target megapixels, min or max side) - Adjust the corresponding value
With Image Input
- Connect an image node to the optional
image
input - Set
use_image_ratio
to Yes to use the image's aspect ratio - Set
use_image_ratio
to No to scale image to selected preset as describe above - Optional image outputs will be scaled
Custom Dimensions
- Select
scaling_mode: custom dimensions
- Set
custom_width
andcustom_height
to desired values - Connected image outputs will be scaled to these exact dimensions
Node Inputs
| Input | Type | Description |
|-------|------|-------------|
| custom_width
| INT | Width when using custom aspect ratio |
| custom_height
| INT | Height when using custom aspect ratio |
| scaling
| COMBO | How to scale dimensions (megapixels/min/max side/aspect ratios) |
| use_image_ratio
| COMBO | Use connected image's ratio (Yes/No) |
| target_megapixels
| FLOAT | Target resolution in megapixels |
| min_side
| INT | Shortest dimension in pixels |
| max_side
| INT | Longest dimension in pixels |
| flip_dimensions
| COMBO | Swap width/height (No/Yes) |
| batch_count
| INT | Number of latent batches to generate |
| image
| IMAGE | Optional: Image to analyze/scale |
Node Outputs
| Output | Type | Description |
|--------|------|-------------|
| width
| INT | Calculated width |
| height
| INT | Calculated height |
| batch_count
| INT | Batch count passthrough |
| empty_latent
| LATENT | Empty latent tensor |
| scaled_image
| IMAGE | Scaled input image (if provided) |
| resolution_info
| STRING | Human-readable resolution summary |
Supported Aspect Ratios
- 1:1 square - Perfect square format
- 4:3 standard - Classic monitor/photo ratio
- 3:2 classic - 35mm film ratio
- 16:9 widescreen - Modern video/monitor standard
- 21:9 ultrawide - Cinematic widescreen
- 3:4 portrait - Vertical standard format
- 2:3 photo - Vertical photo ratio
- 9:16 mobile - Vertical video (TikTok, Instagram Stories)
- 9:21 vertical - Extended vertical format
- 4:5 social - Instagram post format
- 5:7 print - Standard print ratio
Technical Notes
- All output dimensions are automatically rounded to multiples of 8 (required for latent space)
- Minimum dimension is 64 pixels
- Uses bilinear interpolation for high-quality image scaling
- Compatible with all ComfyUI image processing workflows
License
MIT License - see LICENSE file for details.
Changelog
v0.1.0
- Initial release
- Support for 12 aspect ratio presets
- Three scaling modes (megapixels, min/max side)
- Optional image input with intelligent ratio detection
- Real-time image scaling output
Created for the ComfyUI community š