If your workflow needs a predictable pixel budget, use ImageScaleToTotalPixels; if it needs the longer side to reach a chosen dimension, use ImageScaleToMaxDimension. Both nodes preserve the input aspect ratio, but they constrain different quantities. Neither guarantees an arbitrary exact width and height, and the result should be checked by measuring the output image.
Choose the constraint that matters
Use total pixels when your requirement is expressed as an overall image size, such as an approximate megapixel target. Use ImageScaleToMaxDimension when the desired maximum dimension is a specified number: its documentation says the larger dimension is scaled to match largest_size, with the smaller dimension adjusted proportionally. If the downstream specification gives only an upper limit, treat that as a ceiling and verify the measured output does not exceed it; do not assume the limit means the output must equal it. These are different constraints, not interchangeable ways to enter the same number.
For an input with width W and height H, the aspect ratio is W/H and the pixel count is W × H. If the desired maximum dimension is L, the documented proportional scale factor is L / max(W,H). For a target pixel count P, the proportional scale factor is approximately sqrt(P / (W × H)). These formulas give proportional dimensions before converting them to integer pixel dimensions. The cited node documentation does not specify its integer-dimension conversion rule, so use the calculations to estimate and check the actual output after running the workflow; they do not establish a particular rounding method or guaranteed dimensions.
Work through one input both ways
Assume, for illustration, an input image of 2400 × 1600 pixels. Its ratio is 3:2 and it contains 3.84 million pixels.
| Hypothetical target | Proportional calculation | Integer-dimension estimate | Estimated output pixels |
|---|---|---|---|
megapixels = 2 | sqrt(2 / 3.84) ≈ 0.722 | about 1733 × 1155 | about 2.00 million |
largest_size = 1024 | 1024 / 2400 ≈ 0.427 | about 1024 × 683 | about 0.70 million |
These are author-calculated hypothetical estimates, not measured ComfyUI outputs or guaranteed node dimensions. They show why the same source can yield different results: the first target controls area, while the second controls the larger dimension. For an unusually wide or tall image, a fixed maximum dimension can imply a very different total pixel count than expected.
Set up the workflow in order
- Read the actual input width and height from the image or the workflow’s available image information. Calculate the aspect ratio and current pixel count.
- Write down the downstream requirement as one quantity: total megapixels, or longest-side pixels. If a specification names both width and height, check whether they share the input’s aspect ratio before selecting either node.
- Add
ImageScaleToTotalPixelsfor a pixel-budget target and setmegapixels, or addImageScaleToMaxDimensionfor a side-length target and setlargest_size. Connect the same input image and choose the availableupscale_methoddeliberately. - Run the workflow and inspect the output’s actual width and height. Calculate
width × height; compare that value with the pixel target, or comparemax(width,height)with the requested maximum dimension. If the downstream requirement is only an upper limit, verify the measured maximum dimension is no greater than that limit. - Record the observed dimensions alongside the input dimensions and target. Judge the measured result against the downstream requirement; do not infer a rounding rule from the proportional estimate.
Verify the output, not just the setting
Use an image-information node or inspect the saved output’s dimensions, depending on the workflow available to you. The cited documentation describes each node’s target and aspect-ratio behavior, but does not state how integer output dimensions are derived for every input. Do not treat a parameter value or proportional estimate as proof of delivered dimensions.
When neither target is enough
If a delivery specification requires an exact width and height that do not match the source ratio, these nodes’ documented aspect-ratio preservation means that neither target alone expresses the full requirement. Use a separate, appropriate workflow for cropping, padding, or fitting to a canvas, and then check the final dimensions. Do not assume that changing the interpolation method will resolve a geometry mismatch: upscale_method selects a scaling method, while the node’s target input defines the size constraint.
If the measured output is outside your tolerance, first recheck the input dimensions, the chosen node, its target value, and the output you measured. Then adjust the target and run the workflow again. If the size is right but the visual result is unsatisfactory, treat that as a separate resampling-quality decision; the documentation lists methods but does not guarantee a particular method will improve a particular image.
Common questions
Do both nodes keep the image’s proportions?
Yes. The supplied documentation says each preserves the original aspect ratio. That does not mean either can also meet any independently chosen width and height exactly.
Which node should I use for a 2-megapixel target?
Use ImageScaleToTotalPixels and set megapixels to the target. Verify the output’s actual pixel count because integer dimensions may affect the result.
What if the specification gives both a megapixel target and a maximum dimension?
Treat both as acceptance constraints and calculate the expected proportional dimensions for each from the same input. They may not both be met by one setting: ImageScaleToTotalPixels targets total pixels, while ImageScaleToMaxDimension makes the larger dimension match largest_size. Prioritize the downstream hard requirement, select that node, then measure the output width and height, total pixels, and maximum dimension. If the other constraint also has to be met, use an additional suitable geometry step and verify the final output.
Which node should I use when the larger side must be 1024 pixels?
Use ImageScaleToMaxDimension with largest_size set to 1024, then confirm the measured larger output dimension is 1024. If 1024 is only an upper limit, confirm instead that the measured dimension is no greater than 1024. If an exact rectangular canvas is also required, plan an additional geometry step.
Sources and scope
This guide describes the documented node targets and uses hypothetical arithmetic examples. It does not claim a specific ComfyUI version, node rounding behavior, measured output, or image-quality result.
Sources and next step
- ImageScaleToTotalPixels - ComfyUI Built-in Node Documentation
- ImageScaleToMaxDimension - ComfyUI Built-in Node Documentation
This guide interprets public documentation and uses explicitly hypothetical acceptance examples, not application tests. Controls and availability can change; verify the cited manual against your installed version.
For work created in Imagild, carry the input requirements and acceptance checklist into the photo editor. The external software controls discussed above belong to their respective products.