33da43388829ab4afb4088834ab8b16196752a79
ComfyUI Auto Size Plugin
A powerful ComfyUI extension for handling image resolutions. It provides smart, model-aware resolution presets and robust resizing tools, designed for "engineering-grade" automation.
🌟 Features
- Dynamic Dropdowns: The
sizedropdown smartly filters to show only relevant presets for your selectedmodel(e.g., selecting "Flux" hides "Qwen" sizes). - Model-Aware Resolution: Automatically snaps resolutions to specific multiples required by different architectures:
- Flux / Z-Image / Illustrious: Multiples of 32
- Qwen-Image: Multiples of 28
- Smart Custom Logic: Seamlessly switch between presets and custom sizes without fighting the UI.
- Robust Resizing: Includes an advanced
AutoSizenode for images/masks with multiple modes:Center Crop/Edge CropScale to Fit(Letterboxing)Stretch to Fill
📦 Provided Nodes
1. Auto Size Latent
Category: latent/AutoSize
Generates an empty latent tensor for starting a workflow.
- Inputs:
model: Select standard (Flux, Qwen, etc.) or specific architectures.size: Choose a preset (e.g.,Flux - 16:9) orFull Custom.custom_longer_size: Target pixel size for the longer side. Set to 0 to use thesizedropdown.custom_ratio: Target aspect ratio (used only whencustom_longer_size > 0).batch_size: Number of latents to generate.
- Outputs:
latent,width,height,size(string).
2. Auto Size (Image/Mask)
Category: image/AutoSize
Resizes an existing image and/or mask to target dimensions. Perfect for image-to-image workflows.
- Inputs: Same as above, plus:
crop_method: Strategy if aspect ratios don't match (Crop vs Fit vs Stretch).scale_method: Interpolation (Lanczos, Bicubic, Nearest, etc.).image(Optional): Input image to resize.mask(Optional): Input mask to resize.
- Outputs: Resized
image, resizedmask, and dimension info.
🛠️ Installation
- Navigate to your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes - Clone this repository:
git clone https://github.com/jluo-github/comfyui-auto-size.git - Restart ComfyUI.
- Note: If the dynamic dropdowns don't appear immediately, try reloading the browser page.
⚙️ How It Works (The Logic)
The nodes use a Priority System to determine the final resolution:
-
Custom Override (
custom_longer_size > 0):- If you set
custom_longer_sizeto any value greater than 0, the node ignores the Size dropdown. - It calculates the resolution using
custom_longer_size+custom_ratio. - It strictly aligns the result to the selected
model's required multiple (e.g., rounding to nearest 32px or 28px).
- If you set
-
Preset Mode (
custom_longer_size = 0):- If
custom_longer_sizeis 0 (default), the node uses the resolution from the Size dropdown (e.g.,Flux - 16:9).
- If
💻 Development
The project is structured for maintainability and pure Python logic where possible.
nodes/: ComfyUI node definitions.utils/: Core logic (presets, math, resizing) decoupled from ComfyUI.js/: Frontend extensions for dynamic UI behavior.
Running Tests
To verify the math and resize logic:
python -m unittest discover -s tests
License
Made with ❤️ for the ComfyUI community
Languages
Python
91.6%
JavaScript
8.4%