Nodes/ComfyUI-Apt_Preset/Image_target_adjust
ComfyUI Node

Image_target_adjust

Force an image to an exact size — stretch, crop, or pad

By cardenluo·Created 2 years ago·Updated 17 days ago· 309
Image_target_adjust
  • image
  • IMAGE
target_width512
target_height512
multiple64
upscale_method
adjustment_methodstretch
region_positioncenter
pad_backgroundblack

The straightforward sibling in this pack's resize family: no stitch bundle, no restore step, just "make this image exactly this size, using this method." If Image_Resize_sum is the version with a memory (it hands you a receipt to undo itself later), Image_target_adjust is the one-way version - you set a target width and height, pick how to get there, and you're done. Reach for it whenever the destination - an EmptyLatentImage's dimensions, an API's fixed input size, a canvas you're compositing onto - is fixed and you don't need to reverse the operation afterward.

How it works

You give it a target width and height, and one of three ways to hit that target exactly: stretch (the default) distorts the aspect ratio to fill the target dimensions precisely - fast, but it'll squash or stretch the content if the source aspect ratio doesn't match. crop fits the image to the target aspect ratio first by cropping, then scales - no distortion, but you lose content at the edges. pad scales to fit inside the target without cropping or distorting, then fills the leftover space with a background color or leaves it transparent. region_position controls where the crop or pad anchors (center, top, bottom, left, right) - useful when your subject isn't centered in the source.

The inputs and outputs that matter

  • target_width / target_height (INT, 16–4096, step 16, default 512) - the exact output size.
  • multiple (INT, 1–256, default 64) - rounds the final size to a multiple of this. The default of 64 matches Flux's alignment requirement; drop it to 8 for most other diffusion pipelines if you need finer control over the exact target.
  • upscale_method - interpolation algorithm (bicubic default here, plus nearest-exact, bilinear, area, lanczos).
  • adjustment_method - stretch, crop, or pad, as above.
  • Optional region_position (default center) - anchor for crop/pad.
  • Optional pad_background - fill color for pad mode: none (transparent), or a named color (white, black, red, green, blue, yellow, cyan, magenta, gray).

One output: IMAGE, at exactly your target dimensions (rounded to multiple), ready to feed straight into a sampler, a latent encode, or an API call with a fixed input size requirement.

How to install it

ComfyUI Manager: search ComfyUI-Apt_Preset, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset
pip install -r requirements.txt

install.bat is Windows-only; on Linux (comfy.icu's executor included) run pip install -r requirements.txt directly. No model downloads needed.

Common issues

The most common surprise is stretch being the default - if you didn't deliberately pick it and your output looks squashed or stretched, that's why; switch to crop or pad depending on whether you'd rather lose content at the edges or gain letterbox bars. Second, multiple rounds your target, not your source - if target_width/target_height aren't already multiples of it, the actual output size can end up a few pixels off from what you typed, which occasionally surprises people wiring a fixed-size downstream node against these values directly. Read the image dimensions back out with a separate size node if you need the exact final number rather than assuming it matches your input fields precisely.

As with the rest of this pack, a fresh install pulls a large requirements.txt covering the whole 100+-node suite (onnxruntime, gguf, transparent-background, and more) - none of which this specific node needs, but all of which must import for ComfyUI-Apt_Preset to load at all. If the pack fails with IMPORT FAILED on install, check the ComfyUI console for the actual missing-package error before assuming this node is at fault.

CategoryApt_Preset/image/ImgResize

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
target_widthINT51216–4096
target_heightINT51216–4096
multipleINT641–256
upscale_methodCOMBO5 options: bicubic, nearest-exact, bilinear, area, lanczos
adjustment_methodCOMBOstretch3 options: stretch, crop, pad
region_positionoptCOMBOcenter5 options: top, bottom, left, right, center
pad_backgroundoptCOMBOblack10 options: none, white, black, red, green, blue, +4

Outputs (1)

NameTypeDescription
IMAGEIMAGE