Nodes/Duanyll Nodepack/Crop from Padded
ComfyUI Node

Crop from Padded

Crop back to your real aspect ratio

By Duanyll·Created about a year ago·Updated 4 months ago· 2
Crop from Padded
  • padded_image
  • RESTORED_IMAGE
original_scaled_width512
original_scaled_height512

Some pipelines insist on a fixed canvas. A sampler, an attention-based model, or a VAE encode might want an exact resolution, and your source image almost never matches it. The standard trick is to pad the image into the target resolution, do your work, then crop the padding back off so you get out exactly the image you put in. Crop from Padded is the second half of that trick, and it's purpose-built to pair with the same pack's "Pad to Resolution List" node.

Why it exists

ComfyUI's core can handle arbitrary resolutions fine most of the time, but there's a whole class of workflows - fixed-size batch processing, models trained at a specific res, feeding multiple images through the same pipeline - where you want everything normalized to a canvas before processing and restored after. Pad up, process, crop back. This node is the crop-back step, and it exists so you don't hand-roll the arithmetic.

How it works

It's a center crop. The node takes your padded image and the width/height of the content inside it, works out where that content sits (centered, which is exactly where the pack's pad node puts it), and crops it out:

left = (padded_width - original_scaled_width) // 2
top  = (padded_height - original_scaled_height) // 2

That's the whole mechanism - which is why the inputs are the thing you need to get right.

The inputs that matter

  • padded_image - the IMAGE you got back from padding/processing.
  • original_scaled_width - the width of the real content inside the padding.
  • original_scaled_height - same, for height.

Output is RESTORED_IMAGE, an IMAGE you can wire onward to a save node or the next stage.

Here's the trap, and it's a subtle one: those are the scaled dimensions, not the original source dimensions. The pad node doesn't just add borders - it resizes your image to fit inside the target resolution first, then pads the rest. If your 800×1200 portrait gets scaled down to fit a 1024×1024 canvas, the content is now ~683×1024, not 800×1200. If you type 800×1200 into this node, you'll crop off real pixels.

The clean way to avoid all of it: "Pad to Resolution List" outputs PADDED_IMAGE, SCALED_WIDTH, and SCALED_HEIGHT from a single run. Wire the last two straight into this node's original_scaled_width and original_scaled_height. Then the whole pad→process→crop chain is self-consistent even when you change the resolution list. If you got a padded image from some other source, you'll have to supply the numbers yourself.

Installing it

It's part of Duanyll Nodepack. In ComfyUI Manager, search "Duanyll Nodepack" and install, or clone it manually:

cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/duanyll_nodepack

Restart ComfyUI and the node appears under duanyll/image. The pack's README is still the bare cookiecutter template, so expect to lean on the node's behavior (and this page) rather than official docs.

One honest note: if your target resolution is a standard multiple like 1024 or 1536, this is a perfectly fine lightweight alternative to the heavyweight tiling/crop solutions, but if you're doing high-res fixes or detailers, you probably want a proper tiling setup instead. This node is for canvas normalization, not upscaling magic.

Categoryduanyll/image

Inputs (3)

NameTypeDefaultDescription
padded_imageIMAGE
original_scaled_widthINT512
original_scaled_heightINT512

Outputs (1)

NameTypeDescription
RESTORED_IMAGEIMAGE