ComfyUI  >  Nodes  >  ComfyUI Layer Style >  LayerUtility: ImageScaleByAspectRatio

ComfyUI Node: LayerUtility: ImageScaleByAspectRatio

Class Name

LayerUtility: ImageScaleByAspectRatio

Category
😺dzNodes/LayerUtility
Author
chflame163 (Account age: 445 days)
Extension
ComfyUI Layer Style
Latest Updated
6/24/2024
Github Stars
0.6K

How to Install ComfyUI Layer Style

Install this extension via the ComfyUI Manager by searching for  ComfyUI Layer Style
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI Layer Style in the search bar
After installation, click the  Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • High-speed GPU machines
  • 200+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 50+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

LayerUtility: ImageScaleByAspectRatio Description

Resize images while maintaining aspect ratio, with customizable target dimensions and rounding options for visual integrity.

LayerUtility: ImageScaleByAspectRatio:

The LayerUtility: ImageScaleByAspectRatio node is designed to help you resize images while maintaining their aspect ratio. This is particularly useful when you need to scale images to fit specific dimensions without distorting their original proportions. The node offers various methods to determine the target dimensions, such as scaling to the longest or shortest side, width, height, or even a specific number of pixels. Additionally, it provides options to round the dimensions to a multiple of a specified value, ensuring that the resized images meet your exact requirements. This node is essential for AI artists who need to prepare images for further processing or display, as it ensures that the images retain their visual integrity.

LayerUtility: ImageScaleByAspectRatio Input Parameters:

aspect_ratio

This parameter determines the aspect ratio to be used for scaling the image. It can be set to original to maintain the original aspect ratio of the image, custom to use a user-defined aspect ratio, or a specific ratio in the format width:height. The aspect ratio affects how the image will be resized, ensuring that the proportions are kept consistent.

proportional_width

When the aspect_ratio is set to custom, this parameter specifies the width component of the custom aspect ratio. It works in conjunction with proportional_height to define the desired aspect ratio.

proportional_height

When the aspect_ratio is set to custom, this parameter specifies the height component of the custom aspect ratio. It works in conjunction with proportional_width to define the desired aspect ratio.

fit

This parameter determines how the image should be resized to fit within the target dimensions. Options include contain, which scales the image to fit within the dimensions while maintaining the aspect ratio, and cover, which scales the image to cover the entire dimensions, potentially cropping parts of the image.

method

This parameter specifies the resampling method to be used for resizing the image. Options include LANCZOS, bicubic, hamming, bilinear, box, and nearest. Each method offers different trade-offs between quality and performance.

round_to_multiple

This parameter allows you to round the target dimensions to a multiple of a specified value. This is useful for ensuring that the resized images meet specific size requirements. If set to None, no rounding is applied.

scale_to_longest_side

This boolean parameter determines whether the image should be scaled to the longest side. If set to True, the image will be resized such that the longest side matches the specified longest_side value.

longest_side

When scale_to_longest_side is set to True, this parameter specifies the target length for the longest side of the image. The other dimension will be scaled proportionally to maintain the aspect ratio.

image

This parameter accepts the input image to be resized. It is typically provided as a tensor.

mask

This optional parameter accepts a mask image to be resized along with the main image. It ensures that both the image and the mask maintain the same dimensions and aspect ratio.

LayerUtility: ImageScaleByAspectRatio Output Parameters:

resized_image

The resized image is the main output of the node. It is the input image scaled to the target dimensions while maintaining the specified aspect ratio. The output is typically provided as a tensor.

resized_mask

If a mask was provided as an input, the resized mask is the output. It is the input mask scaled to the same dimensions as the resized image, ensuring consistency between the image and the mask.

LayerUtility: ImageScaleByAspectRatio Usage Tips:

  • To maintain the original aspect ratio of an image, set the aspect_ratio parameter to original.
  • Use the fit parameter to control how the image fits within the target dimensions. Contain is useful for ensuring the entire image is visible, while cover is better for filling the entire space.
  • Experiment with different resampling methods using the method parameter to find the best balance between quality and performance for your specific use case.
  • If you need the resized image dimensions to be a multiple of a specific value, use the round_to_multiple parameter to achieve this.

LayerUtility: ImageScaleByAspectRatio Common Errors and Solutions:

Invalid aspect ratio format

  • Explanation: The aspect_ratio parameter was set to a value that does not follow the width:height format.
  • Solution: Ensure that the aspect_ratio is specified in the correct format, such as 16:9 or 4:3.

Unsupported resampling method

  • Explanation: The method parameter was set to a value that is not supported.
  • Solution: Choose a valid resampling method from the available options: LANCZOS, bicubic, hamming, bilinear, box, or nearest.

Image or mask not provided

  • Explanation: The image parameter was not provided, or the mask parameter was expected but not provided.
  • Solution: Ensure that the input image is provided. If a mask is required, make sure to provide it as well.

Dimension rounding error

  • Explanation: The round_to_multiple parameter was set to a non-integer value.
  • Solution: Ensure that the round_to_multiple parameter is set to an integer value or None.

LayerUtility: ImageScaleByAspectRatio Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI Layer Style
RunComfy

© Copyright 2024 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals.