LayerUtility: ImageScaleByAspectRatio Node Documentation
Overview
The LayerUtility: ImageScaleByAspectRatio node is a component within the ComfyUI interface that allows users to resize images and masks while maintaining or altering their aspect ratio based on user preferences. This node is particularly useful in scenarios where maintaining specific dimensions, scaling uniformly, or preparing images for different display sizes is required.
Node Functionality
This node is designed to:
- Scale images and masks to a specified aspect ratio.
- Offer flexibility in scaling methods and modes.
- Provide options to round dimensions to specific multiples, ensuring compatibility with various systems or requirements.
- Facilitate image processing workflows by integrating seamlessly with other nodes within ComfyUI.
Inputs
The node accepts the following inputs:
- aspect_ratio (required): Determines the target aspect ratio for the scaling operation. Options include predefined ratios such as '1:1', '16:9', and '3:2', as well as 'original' to keep the image's current aspect ratio or 'custom' to define a personalized ratio.
- proportional_width (required): When 'custom' ratio is selected, this defines the width ratio. Integer values from 1 to 999 can be specified.
- proportional_height (required): Similar to proportional_width, this defines the height ratio for a 'custom' aspect ratio. Also accepts integer values from 1 to 999.
- fit (required): The fit mode dictates how the scaling is applied. Options include 'letterbox', 'crop', and 'fill'.
- method (required): The resampling method used for resizing, such as 'lanczos', 'bicubic', or 'nearest'.
- round_to_multiple (required): Round the dimensions to a multiple of a specified number (e.g., 8, 16, 32) or 'None' to disable rounding.
- scale_to_longest_side (required): A boolean option that allows the image to be scaled based on its longest side.
- longest_side (required): Specifies the length of the longest side when scaling according to this dimension. Accepts integer values from 4 to 999999.
- image (optional): The image to be scaled. If not provided, the mask is used (if available).
- mask (optional): The mask to be scaled. It works in conjunction with or independently from the image input.
Outputs
The node produces the following outputs:
- image: The scaled image based on the input parameters.
- mask: The scaled mask, if provided and processed.
- original_size: An array containing the original width and height of the processed image or mask.
- width: The final width of the scaled image or mask.
- height: The final height of the scaled image or mask.
Usage in ComfyUI Workflows
The LayerUtility: ImageScaleByAspectRatio node can be seamlessly integrated into ComfyUI workflows to process images and masks according to specific design or presentation needs. It is particularly valuable in workflows where consistent image dimensions are necessary, such as:
- Preparing images for web display where specific aspect ratios must be adhered to.
- Standardizing dimensions for print or digital distribution.
- Pre-processing images for machine learning models, where input dimensions need to be uniform.
Special Features and Considerations
- Aspect Ratio Flexibility: This node accommodates both predefined and custom aspect ratios, offering versatile usage for diverse projects.
- Scaling Methods: Users can choose from several resampling methods, catering to different quality and performance requirements.
- Rounding Options: Rounding dimensions to user-specified multiples ensures compatibility with various grid or layout systems.
- Error Handling: The node provides logs for mismatched dimensions and other potential errors, aiding in debugging and configuration.
The LayerUtility: ImageScaleByAspectRatio node is an essential tool for maintaining refined control over image and mask dimensions within the ComfyUI environment. By offering a robust set of features and customization options, it empowers users to achieve precise scaling results tailored to their project needs.