KJNodes/imagegenerated

Image Transform KJ(ImageTransformKJ)

Interactive image transform node: crop, resize, pad, and rotate. Connect an image input — the preview appears automatically. Cropping: Click + drag to draw a crop region. Drag inside to move, drag edges/corners to resize. Right-click to delete a region. Ctrl to snap to grid. Shift + resize to constrain aspect ratio. Alt + resize to resize symmetrically. Padding: Shift + drag to adjust padding position. Rotate button enables rotation cross (drag to rotate, right-click to reset). Set target_width/height to resize output (0 = keep original). Use keep_proportion to control how the image fits the target. Use extra_padding to add padding with color or edge fill (clamp/repeat/mirror).

Image Transform KJ

image
mask
keep_proportion
extra_padding
invert_crop
cropped
cropped_mask
bbox
bbox_mask
width
height
target_width
0
target_height
0
upscale_method
lanczos
divisible_by
2
bboxes
STRING
pad_x
0.50
pad_y
0.50
edge_mode
clamp
pad_x
0.50
pad_y
0.50
width_mult
1.00
height_mult
1.00
edge_mode
clamp
edge_mode
clamp
KJNodes

Description

The Image Transform KJ node provides an interactive, in‑preview interface for cropping, resizing, padding, and rotating images (and optional masks).
Connect an image input and the preview appears automatically, allowing you to draw crop regions, adjust padding placement, and apply rotation directly in the preview.

Cropping:

  • Click + drag to draw a crop region.
  • Drag inside the region to move it; drag edges or corners to resize.
  • Right‑click to delete a region.
  • Hold Ctrl to snap to a grid.
  • Hold Shift while resizing to constrain the aspect ratio.
  • Hold Alt while resizing to resize symmetrically around the center.

Padding:

  • Hold Shift and drag the content inside the preview to adjust the padding position (equivalent to changing pad_x and pad_y).

Rotation:

  • Click the Rotate button to enable a rotation cross. Drag to rotate; right‑click to reset rotation.

Inputs

NameTypeDefaultTooltip / Description
imageIMAGE / MATCHTYPEThe image (or mask‑compatible tensor) to transform.
maskMASKoptionalOptional mask to transform alongside the image.
target_widthINT0Target output width. 0 = keep original width.
target_heightINT0Target output height. 0 = keep original height.
upscale_methodCOMBOlanczosInterpolation method for resizing: nearest-exact, bilinear, area, bicubic, lanczos.
keep_proportionDYNAMICCOMBOControls how the content fits the target dimensions (e.g. keep aspect ratio, stretch, etc.). Options depend on the backend – adjust to match your workflow.
divisible_byINT2Ensures output dimensions are divisible by this value (0 = no constraint; max 512).
extra_paddingDYNAMICCOMBOEnables additional padding around the cropped content. When active, pad_x, pad_y, and edge_mode are used.
invert_cropDYNAMICCOMBOWhen enabled, the crop region is inverted (the area outside the crop is kept / processed).
bboxesSTRING""Optional pre‑existing bounding boxes (e.g. from a detection node) to be applied or modified.
pad_xFLOAT0.5Horizontal position of content inside the padded area (0 = left, 0.5 = center, 1 = right). Also adjustable interactively by Shift+dragging content.
pad_yFLOAT0.5Vertical position of content inside the padded area (0 = top, 0.5 = center, 1 = bottom). Also adjustable interactively by Shift+dragging content.
edge_modeCOMBOclampHow to fill padding areas: clamp (extend edge pixels), repeat (tile the image), mirror (tile with mirroring).
width_multFLOAT1.0Multiply the crop width by this factor. Range [0.01, 16], step 0.05.
height_multFLOAT1.0Multiply the crop height by this factor. Range [0.01, 16], step 0.05.

Note: The interactive preview updates in real time. Changes to pad_x, pad_y, width_mult, height_mult, and rotation are reflected immediately.

Outputs

Output #TypeDescription
1IMAGE (same type as input)The transformed image after crop, resize, pad, and rotation.
2MASKThe transformed mask (if a mask input was provided; otherwise an empty mask).
3BBOXBounding box coordinates of the applied crop region (format depends on backend, typically [x1, y1, x2, y2] or similar).
4MASKA mask corresponding to the cropped region (useful for compositing or further processing).
5INTWidth of the final crop region.
6INTHeight of the final crop region.

Usage Notes

  • Interactive cropping is the intended primary workflow: the preview allows intuitive selection of crop regions. The bboxes input can be used to supply or override the region programmatically.
  • Resizing behavior: When both target_width and target_height are 0, the output retains the cropped / padded size without additional upscaling. To resize to a specific resolution, set one or both targets and choose an upscale_method. The keep_proportion option determines whether the image is stretched, cropped to fit, or padded to fill the target.
  • Padding is only applied when extra_padding is enabled. Use pad_x / pad_y to position the content, and edge_mode to control how the padding area is filled.
  • Rotation is applied after cropping and before resizing/padding. The rotation cross in the preview gives fine control; the rotation is stored internally and can be adjusted per‑session.
  • The divisible_by parameter is useful for aligning dimensions to model‑friendly sizes (e.g., multiples of 8, 16, 32). Setting it to 0 disables the constraint.
  • Coordinate snapping: Hold Ctrl while drawing or moving a crop rectangle to snap its position and size to a grid (grid spacing is determined by the node’s internal step). This helps align crops to a regular tiling.

All parameters that affect the final output are exposed as inputs, so the node can be used both interactively and in fully automated pipelines by connecting appropriate values (e.g., from other nodes that output bounding boxes or dimensions).

Comments

Sign in with GitHub to join the discussion.

Loading comments…
Image Transform KJ (ImageTransformKJ) - ComfyUI-KJNodes | ComfyUI Wiki