Nodes/ComfyUI WPX Nodes/RectangleContour
ComfyUI Node

RectangleContour

Grid-fill any rectangle

By WangPengxing·Created 2 years ago·Updated 2 years ago· 0
RectangleContour
  • rectangle_image
  • stickers
  • main_sticker
  • image
n_scales4
sticker_size280
main_sticker_size450
cell_size_factor0.45
crop_imagefalse
padding0

RectangleContour is the square-cornered member of the WPX sticker-arrangement family. Where AnimalContour traces an organic outline and CircleContour builds concentric rings, this one detects a rectangle in your input image and fills it with a tidy grid of stickers - nested rectangles inside rectangles, like a matryoshka sticker sheet. It's the node you reach for when you want order, not scatter: product sticker packs, card backgrounds, and anything where the composition should read as deliberate rows rather than random tiling. Same pack (ComfyUI WPX Nodes), same story: no model, no key, pure CPU.

How it works

The node binarizes your rectangle_image, finds the largest contour, and takes its bounding box as the rectangle. It then generates n_scales concentric rectangles that shrink toward the center, keeping themselves centered. Inside each rectangle it lays a regular grid - the grid cell size is sticker_size × cell_size_factor - and drops a sticker at every grid point with a small random offset and a slight rotation. The one genuinely clever bit: stickers sitting on the rectangle's edges are aligned flush to the boundary and un-rotated, so the outer border reads as a clean frame instead of a jagged mess. After the nested layers, the main_sticker is pasted dead-center, scaled by main_sticker_size.

The inputs that matter

  • rectangle_image - the shape that defines the box. Any rectangle-ish silhouette whose largest contour is the rectangle you mean.
  • stickers - the fill pool. A batch of sticker images the node cycles through.
  • main_sticker - the centerpiece.
  • n_scales (4) - how many nested rectangle layers.
  • sticker_size (280) and cell_size_factor (0.45) - sticker long side and how much of a grid cell a sticker fills. Factor too high and stickers overlap heavily; too low and the grid gets gappy.
  • main_sticker_size (450) - centerpiece scale.
  • crop_image (bool) + padding - trims transparent margins off sticker PNGs before arranging.

Output: a single image (RGBA), wire it to a preview or save node.

Installing

ComfyUI Manager → search "ComfyUI WPX Nodes" → install → restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/WangPengxing/ComfyUI_WPX_Node
# restart ComfyUI

No weights, no requirements file. The recurring pack gotcha: rtree and scipy are imported at startup, and if either is missing the entire WPX_Node menu disappears. pip install rtree scipy and restart.

Troubleshooting

  • The grid isn't filling the whole rectangle. cell_size_factor is low, so cells are smaller than the rectangle wants to be filled. Raise it toward 0.5–0.6.
  • Stickers spill past the edge. The outer layer aligns flush to the boundary, but a very wide sticker can still peek out. Shrink sticker_size relative to your rectangle.
  • [DEBUG] spam in the console - normal for this pack; the author left debug prints in every node.

Same caveats as the rest of the pack: 0.0.1, one early-2025 update, zero community footprint. It's a niche utility with a narrow job, but for "fill this box with a neat grid of stickers" there's nothing in the mainstream ecosystem that does it more directly.

CategoryWPX_Node/main_image

Inputs (9)

NameTypeDefaultDescription
rectangle_imageIMAGE
stickersIMAGE
main_stickerIMAGE
n_scalesINT41–10
sticker_sizeINT2801–1000
main_sticker_sizeINT4501–1000
cell_size_factorFLOAT0.450–1
crop_imageBOOLEANfalse
paddingINT00–1000

Outputs (1)

NameTypeDescription
imageIMAGE