Image Edge Crop/Pad
The one node that pads to divisible and tells you where the original was
- image
- image
- mask
Half of ComfyUI's "why won't it encode" errors are resolution problems - the VAE or the edit model wants dimensions divisible by 8 (or 16, or 64) and your image isn't. Image Edge Crop/Pad is the fix with a twist: one signed value per edge, negative crops in, positive pads out, everything snaps to a multiple you choose, and it also hands you a mask that records where the original pixels are. That last bit is the part that saves you.
It's from ComfyUI 1hewNodes (solo dev 1hew, bilingual README, active development). A genuinely well-thought-out utility node.
How it works
Five sliders describe the edges: uniform_amount applies to all four sides at once, then top_amount, bottom_amount, left_amount, right_amount adjust individually (they add to the uniform value). Negative amounts crop inward - you lose pixels - and positive amounts pad outward with pad_color. Each resulting edge is snapped to divisible_by (default 8), so padding 5px on a 1021px-wide image gets you a clean 1024 instead of a floating-point disaster.
There's a nice fractional shortcut: an amount with absolute value under 1 is treated as a fraction of the dimension (0.1 on a 1000px image = 100px). So uniform_amount = 0.5 splits an image in half as a crop, or... well, pad a 1000px image to 1500. It's the fastest way to hit "crop to center 50%."
The mask output is the real star: it's all-black where the original image is, all-white where you cropped or padded. Feed that to a composite node later and you can put your processed image back into the original frame exactly - or use it to know precisely which pixels were fabricated by padding. Handy when an edit model has redrawn your whole padded canvas and you want to keep only the region you actually care about.
The inputs that matter
- image - source. As of v3.21.1 it accepts RGBA, with pad defaulting to transparency.
- uniform_amount / top / bottom / left / right_amount - signed px (or fractions under 1). This is the entire control surface.
- pad_color - fill for padded areas (default
"0.0", black; supportstransparentand 4-component strings like255,0,0,128). - divisible_by - the multiple every edge snaps to (default 8).
Outputs: image (cropped/padded) and mask (original-region map).
Installing it
ComfyUI Manager → search "1hew" / "ComfyUI 1hewNodes" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
Heavy requirements across the pack (opencv, scikit-image, plus ultralytics/rembg for detection nodes) make first install slow; this node needs numpy/PIL/torch. No models. Current ComfyUI required (modern node API).
Gotchas
- The mask is inverted from what you might guess - black = original, white = added/removed. Read the README's framing or you'll composite the wrong region.
- Zero everywhere = passthrough - all-zeros returns the image with a full-black mask. Not a bug.
- Divisible snapping can eat a pixel - a crop that lands on 1023 gets snapped down, not up. If you're exactly 1px over a boundary, expect the snap, don't fight it.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| uniform_amount | FLOAT | 0.00-8192–8192 | — |
| top_amount | FLOAT | 0.00-8192–8192 | — |
| bottom_amount | FLOAT | 0.00-8192–8192 | — |
| left_amount | FLOAT | 0.00-8192–8192 | — |
| right_amount | FLOAT | 0.00-8192–8192 | — |
| pad_color | STRING | 0.0 | — |
| divisible_by | INT | 81–1024 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |