DaSiWa Torch Resize:
DaSiWa_TorchResize resizes ComfyUI images and image batches using PyTorch. You can enlarge or reduce an image, or fit it into a chosen canvas size while deciding whether to preserve its proportions, crop the edges, add padding, or stretch it. It offers several resampling methods, including a cached Lanczos method, so you can choose an approach suited to photographs, illustrations, or hard-edged pixel art. It also processes large batches in chunks to help manage memory. The node’s goal is to give you predictable image dimensions and control over how the finished image looks within them.
DaSiWa Torch Resize Input Parameters:
image
The IMAGE to resize. Connect a ComfyUI image or image batch; every image in the batch receives the same resizing treatment. The node expects image data with a batch dimension, height, width, and either 1, 3, or 4 color channels. This input is required and has no default.
size_mode
Chooses how you specify the new size. Options are Multiplier and Target resolution; the default is Multiplier. Multiplier scales the source dimensions by a factor while preserving their proportions. Target resolution uses the target width and height as a box and applies the selected aspect-handling method.
aspect_mode
Controls how the image relates to the target box when size_mode is Target resolution. Options are Stretch, Fit, Fill and crop, Fit and pad, and Long side with divisible crop; the default is Fit. Stretch fills the box but can distort proportions. Fit preserves the exact source ratio within the box, potentially producing a smaller image. Fill and crop fills the box and removes overflow. Fit and pad preserves the image within a full-size canvas. Long side with divisible crop scales using the source image’s longer side and crops the other dimension to an allowed multiple. This setting does not affect Multiplier mode.
target_width
Sets the width, in pixels, of the target box in Target resolution mode. Its default is 1920, with a minimum of 1, maximum of 16384, and step of 1. Depending on aspect_mode and divisible_by, the resulting image may be narrower than this value or the box width may be rounded down. It is ignored in Multiplier mode.
target_height
Sets the height, in pixels, of the target box in Target resolution mode. Its default is 1080, with a minimum of 1, maximum of 16384, and step of 1. Fit can produce an image shorter than this value, while divisibility requirements can round the box height down. It is ignored in Multiplier mode.
scale_multiplier
Sets the scale factor in Multiplier mode. Its default is 2.0, with a minimum of 0.01, maximum of 16.0, and step of 0.01. For example, 2.0 aims to double both dimensions, while 0.5 aims to halve them. The calculated dimensions are rounded to whole pixels and then floored to multiples of divisible_by; a very small result can therefore cause an error. It is ignored in Target resolution mode.
interpolation
Selects how new pixel values are calculated. Options are Nearest, Bilinear, Bicubic, Area, and Lanczos; the default is Lanczos. Nearest selects nearby source pixels without blending and is useful when you want to retain hard pixel edges. The other methods blend or combine pixels, giving you different treatments of detail and smoothness. The node uses PyTorch interpolation for all options except Lanczos, for which it uses a separable resampling method with cached weights.
gamma_correct
Determines whether eligible image colors are converted from sRGB to linear light before resizing and converted back afterward. The default is true; the available values are true and false. This changes how blended colors are calculated and can be useful when resizing gradients or high-contrast edges. It does not apply to Nearest interpolation. For four-channel images, the alpha channel is resized separately without this conversion.
divisible_by
Sets a required multiple for output width and height. Its default is 1, with a minimum of 1, maximum of 4096, and step of 1. Use 1 when you do not need a divisibility constraint; use a larger value when a later workflow stage requires dimensions divisible by that number. The node floors applicable dimensions to a multiple, so the result can be smaller than the requested size. In Fit mode, it preserves the source ratio exactly while seeking dimensions that satisfy the multiple, which may make the result substantially smaller or produce an error if the box is too small.
pad_color
Sets the canvas color used only by Fit and pad. The default is 0, 0, 0, meaning black; no interface minimum or maximum is specified. Enter three comma-separated channel values on a 0–255 scale, such as 255, 255, 255 for white. The implementation converts each component to an integer and limits it to that scale. If the text cannot be parsed, it uses black. For a four-channel image, the added padding has fully opaque alpha.
crop_position
Sets where the image is anchored when cropping overflow or placing it on a padded canvas. Options are center, top-left, top, top-right, left, right, bottom-left, bottom, and bottom-right; the default is center. For example, top keeps the upper part of an image when vertical cropping is needed, while top-left places a fitted image against the upper-left corner of a padded canvas. It affects Fill and crop, Fit and pad, and Long side with divisible crop, but not the other aspect modes or Multiplier mode.
batch_size
Controls how many images are resized in each processing chunk. Its default is 0, with a minimum of 0, maximum of 4096, and step of 1. At 0, the node chooses a chunk size automatically using max_batch_megapixels. A positive value sets the chunk size directly; reducing it can help when processing a batch exceeds available memory. It changes processing behavior, not the requested output dimensions.
max_batch_megapixels
Sets the pixel budget used to choose an automatic chunk size when batch_size is 0. Its default is 16.0, with a minimum of 0.25, maximum of 512.0, and step of 0.25. The calculation uses the larger of the source or output pixel count per frame and treats one megapixel as 1,048,576 pixels. A lower value generally means fewer frames per chunk, which may help manage memory. It does not set an absolute limit on all memory used during resizing.
cache_size
Sets how many Lanczos weight sets the shared cache retains. Its default is 64, with a minimum of 1, maximum of 512, and step of 1. Reusing weights can avoid recalculating them when the same source and destination sizes recur. A larger cache can retain more size combinations but also consumes more memory. This setting is chiefly relevant when interpolation is Lanczos.
DaSiWa Torch Resize Output Parameters:
image
The resized IMAGE, returned in the same batch-oriented image format with height, width, and color channels. It contains the selected resize result, including any requested crop or padding. The node retains the input batch count and channel count, and limits returned values to the 0–1 range. Its dimensions reflect the chosen mode and any divisible_by constraint, so they may differ from the target box dimensions.
DaSiWa Torch Resize Usage Tips:
- For a proportional enlargement or reduction, choose
Multiplierand setscale_multiplier. Leavedivisible_byat1unless a later node needs a particular pixel multiple. - To keep the whole image visible without adding borders, choose
Target resolutionwithFit. Check the resulting dimensions if you use a largedivisible_by: preserving the exact ratio and satisfying the multiple can require a much smaller result. - For an exact target canvas without distorting the subject, use
Fill and croporFit and pad. Choosecrop_positionto protect the part of the image that matters, and setpad_colorwhen padding is used. - Use
Stretchonly when filling the target dimensions matters more than preserving the source proportions. It can make subjects appear wider or taller. - Try
Nearestfor artwork whose individual pixel boundaries should stay hard-edged. For blended resizing, compare the available interpolation options on a representative image;gamma_correctaffects blended colors but not Nearest results. - For large image batches, start with
batch_sizeat0. If memory use remains too high, lowermax_batch_megapixelsor set a small positivebatch_size. Processing in chunks does not eliminate the memory needed for the complete output.
DaSiWa Torch Resize Common Errors and Solutions:
DaSiWa Torch Resize expects IMAGE data shaped [batch, height, width, 1/3/4 channels].
- Explanation: The connected data is not a supported ComfyUI-style image batch, or it does not have 1, 3, or 4 channels.
- Solution: Connect an IMAGE output from a compatible node. If another tool produced the data, check that it is arranged as batch, height, width, then channels.
Target width and height must be at least divisible_by.
- Explanation: After a requested dimension is rounded down to a multiple of
divisible_by, its value becomes zero. This can happen with a small target box or a small multiplier. - Solution: Reduce
divisible_by, increase the target dimensions, or increasescale_multiplier.
Target box is too small to preserve aspect ratio at divisible_by.
- Explanation: In
Fitmode, the node cannot fit an image that both preserves the source ratio exactly and has dimensions divisible by the chosen value inside the target box. - Solution: Lower
divisible_by, enlarge the target box, or choose another aspect mode if an exact source ratio is less important than the requested canvas.
Target height is too small for divisible AR scaling.
- Explanation: With
Long side with divisible cropon a landscape-oriented image, the available height becomes smaller than one allowed multiple after scaling and flooring. - Solution: Increase
target_height, reducedivisible_by, or use another aspect mode.
Target width is too small for divisible AR scaling.
- Explanation: With
Long side with divisible cropon a portrait-oriented image, the available width becomes smaller than one allowed multiple after scaling and flooring. - Solution: Increase
target_width, reducedivisible_by, or use another aspect mode.
Unknown size_mode.
- Explanation: The node received a size mode other than
MultiplierorTarget resolution. This is unlikely when selecting from the current interface, but may occur with incompatible or altered workflow data. - Solution: Re-select a supported
size_modein the node and check that the workflow uses a compatible version of the node.
Unknown aspect_mode.
- Explanation: In Target resolution mode, the node received an aspect mode outside its listed options.
- Solution: Re-select one of the available
aspect_modeoptions and check any imported workflow values.
CUDA out of memory or a device memory allocation error
- Explanation: The resize operation or its full output needs more available device memory than PyTorch can allocate. The exact message depends on the device and PyTorch environment.
- Solution: Reduce the target size or multiplier, process fewer source images, or lower the automatic batch budget through
max_batch_megapixels. You can also try a small positivebatch_size, though the full output must still fit in memory.
An assertion error when resizing an empty image batch
- Explanation: The implementation expects at least one image. With zero frames, its processing loop creates no output and the final assertion fails.
- Solution: Check the preceding node and provide an IMAGE batch containing at least one image.
