Nodes/JPS Custom Nodes for ComfyUI/Crop Image TargetSize (JPS)
ComfyUI Node

Crop Image TargetSize (JPS)

Crop to an exact width and height, not just a square

By JPS-GER·Created 3 years ago·Updated 2 years ago· 100
Crop Image TargetSize (JPS)
  • image
  • IMAGE
target_w0
target_h0
crop_position
offset0
interpolation
sharpening0.00

The pack's README talks up a "Crop Image Square" node for square-aspect crops (handy for CLIP Vision inputs like IP-Adapter or Revision, which typically expect square images). This node is its general-purpose sibling: instead of forcing a square, it crops to whatever exact pixel width and height you specify, using the same positioning logic - pick a side to crop from, fine-tune with an offset, choose how the resize interpolates, and optionally sharpen the result.

You give it an image, a target_w and target_h (both in steps of 8, matching the pixel granularity most diffusion pipelines expect), a crop_position (center, top, bottom, left, or right - which edge the crop favors when the source doesn't match the target aspect ratio), an offset to nudge the crop window further in either direction, an interpolation method for the resize step (lanczos, nearest, bilinear, bicubic, area, or nearest-exact), and a sharpening amount from 0 to 1 to counteract the softening that resizing - especially downsizing - tends to introduce. The output is a single cropped, resized IMAGE.

Why the target-size version matters. SDXL and its finetunes were trained on a specific shortlist of aspect-ratio buckets (1024x1024, 1152x896, 1216x832, and so on), not on arbitrary rectangles, and feeding img2img or ControlNet a source image that's off that grid is exactly what produces the warped-anatomy, stretched-composition look the model gets blamed for. Cropping to an exact target width and height - rather than just forcing a square - is what actually lets you land a real-world photo onto one of those trained buckets while controlling which part of the image survives the crop.

Where it fits. Pair it with Get Image Size (JPS) and SDXL Recommended Resolution Calc (JPS): read your source image's dimensions, calculate the nearest SDXL-trained resolution, then feed that width and height straight into this node's target_w/target_h to actually produce an image at that size, with the crop position and offset giving you control over what gets kept versus trimmed away.

Installing it. ComfyUI Manager, search "JPS Custom Nodes for ComfyUI," or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/JPS-GER/ComfyUI_JPS-Nodes.git

Restart ComfyUI and find it under JPS Nodes/Image. Remove any older copy of the pack first if reinstalling. No models needed - the resize and sharpening operate through standard image-processing libraries ComfyUI already ships with, nothing extra to download.

Troubleshooting. If your subject ends up partially cropped out, start with crop_position and offset - center is a safe default when the subject is roughly centered, but a portrait shot with the subject high in the frame will usually want top instead, and the offset value is there for exactly the cases where none of the five fixed positions land quite right. If results look soft after a heavy downscale, nudge sharpening up incrementally rather than maxing it immediately - too much sharpening on top of a resize introduces its own artifacts (halos around edges), so it's a "small amount, check the result" setting rather than a set-and-forget one.

CategoryJPS Nodes/Image

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
target_wINT0
target_hINT0
crop_positionCOMBO5 options: center, top, bottom, left, right
offsetINT0-2048–2048
interpolationCOMBO6 options: lanczos, nearest, bilinear, bicubic, area, nearest-exact
sharpeningFLOAT0.000–1

Outputs (1)

NameTypeDescription
IMAGEIMAGE