ComfyUI Node

Pt Crop

The node that will teach you ComfyUI images aren't what this pack wants

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Crop
  • tens
  • TENSOR
height0
width0

Pt Crop cuts a tensor down to a target height x width, and it's the node that will introduce you to the pack's most important concept: a ComfyUI IMAGE is not the same thing as this pack's TENSOR. ComfyUI images are (batch, height, width, channels). This pack's tensor ops expect channels-first - (c, h, w) for a single image or (b, c, h, w) for a batch. Wire an image straight into this node and you'll get a runtime error about rank or an output that's silently nonsense.

The fix is a standard two-hop dance that you'll use for every image-processing node in this pack:

  1. PtFromImage - casts the ComfyUI IMAGE to a TENSOR (a pure cast, layout unchanged).
  2. PtPermute with [0, 3, 1, 2] - reorder (b, h, w, c) to (b, c, h, w).
  3. Crop.
  4. PtPermute with [0, 2, 3, 1] - back to (b, h, w, c).
  5. PtToImage - cast back.

(Note: the pack's own docs list the permute indices in a couple of spots with the forward/backward pair swapped - trust the shapes, not the memory. PtShowSize is your friend when in doubt.)

Inputs

  • tens - a TENSOR in (c, h, w) or (b, c, h, w) layout.
  • height - target crop height (INT, 1–16384).
  • width - target crop width (INT, 1–16384).

Output: the cropped TENSOR.

Where people get burned

Two things. First, the crop size must be smaller than the image - the node throws "Specified crop size exceeds tensor dimensions" if you ask for more than you have. Second, despite the source containing what looks like centering math, the bounds check guarantees that math always resolves to zero - meaning the crop is taken from the top-left corner, not the center. If you expected a center crop, you'll be cropping faces off subjects until you notice. The pack has no built-in center-crop helper here, so if you need one, build it from PtCrop + PtPermute + some index math yourself.

Installing it

Ships in ComfyUI-Pt-Wrapper by Hide Inada (HowToSD). ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Heavy dependency tree (transformers, datasets, scikit-learn, scipy, gensim, pandas, peft, accelerate...). If Manager's install fails, pip install -r requirements.txt in the clone. No model downloads for this node.

CategoryData Analysis

Inputs (3)

NameTypeDefaultDescription
tensTENSOR
heightINT01–16384
widthINT01–16384

Outputs (1)

NameTypeDescription
TENSORTENSOR