Nodes/Comfyui_PDuse/PD:Image Crop Location
ComfyUI Node

PD:Image Crop Location

Image Crop Location — pixel-exact crops with a hidden 8-pixel favor

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD:Image Crop Location
  • image
  • Result
x0
y0
width256
height256

PD:Image Crop Location is the "give me the rectangle at these coordinates" node: x, y, width, height, and out comes exactly that region. If you know where the content is - a face you detected, a tile in a grid, a region you measured once - this is the fastest way to extract it without any guessing about alignment.

There are a dozen crop-by-coords nodes out there, so the interesting part of this one is the detail most people discover the hard way: it rounds the crop down to a multiple of 8, using a bilinear resize, after slicing. Ask for 1000×1000 and you can get back 992×992. That's a feature in disguise for AI work - latent-friendly dimensions divisible by 8 mean less resizing surprise downstream - but it means "pixel-exact" comes with a small asterisk.

How it works

The slice is plain: image[:, y:y+height, x:x+width, :], clamped to the image bounds, with the region beyond an edge silently trimmed. If x or y starts past the edge, it raises a ValueError and kills the run rather than returning garbage - annoying mid-run, but better than a mystery crop. Then the 8-multiple step kicks in: if the cropped dims aren't divisible by 8, it interpolates the crop down to the nearest multiple of 8. Because that's a resize, not a trim, a 1000px crop can come back 8px smaller with a barely-visible re-sample.

The inputs that matter

  • image (IMAGE) - the source.
  • x / y (INT, default 0) - top-left corner of the crop.
  • width / height (INT, default 256 each) - size of the region.

One output: Result (IMAGE).

Where it fits

Region extraction for detailer-style loops is the natural home: detect a face, feed its bbox coordinates in here, crop, upscale, re-render, paste back - the classic "zoom in, fix, paste" loop the KB's masking essay describes. Because the coordinates are plain INTs you can compute them upstream (from a BOUNDING_BOX primitive or another node) and let the crop chase the content.

Two honest notes: there's no mask input here - if you need the crop and its mask synchronized, PDImageCropLocation_V2 in the same pack does that (and mints a mask for you). And the 8-multiple resize means the crop dims you get back may not be exactly what you asked for; if you need a precise pixel-for-pixel cut, prefer the pack's PD:Image Crop_custom, which slices without resampling.

Install

ComfyUI Manager: search PDuse (repo 7BEII/Comfyui_PDuse), install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt

Restart and it shows as PD:Image Crop Location under PDuse/Image. Precise, no-frills, and just opinionated enough about 8s to keep your latents happy.

CategoryPDuse/Image

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
xINT00–10000000
yINT00–10000000
widthINT2561–10000000
heightINT2561–10000000

Outputs (1)

NameTypeDescription
ResultIMAGE