Paste Into Frame
Paste generated art into a card's cutout, without the seam-work
- patch
- frame
- mask
- IMAGE
If you make custom card art - Yu-Gi-Oh frames, game cards, any template with a window cut out of it - you know the manual version of this job: generate art, size it, paste it, then spend ten minutes erasing the bits that spill over the border. Paste Into Frame is the node that does the whole paste step for you. Give it the generated art (patch), the card or frame (frame), and a mask where white = the hole, and it finds the hole, trims your art to fit, and composites it behind the frame so the border stays pixel-perfect.
It's the second half of the draw_tools (a.k.a. ygo_tools) pack's card pipeline. The first half, Detect Inner Box, measures the hole and gives you exact dimensions to generate at; this node finishes the job. Together they're the "render the region at full res, composite it back" approach that still beats whole-frame instruction editing when you need everything outside the hole untouched.
How it works
Mechanically it's straightforward and it's the kind of thing that's easy to get wrong by hand:
- The mask is binarized at a threshold of 127 and the largest white connected region is found - that's your hole.
- The patch is center-cropped to the hole's exact width and height.
- The patch goes onto a transparent layer at the hole's position, clipped to the hole's shape.
- The mask is inverted and used as the frame's alpha channel - border opaque, hole transparent.
- The two layers are alpha-composited, so the patch shows through the hole and the frame covers everything else.
The whole thing runs per-image, so you can throw a batch of cards through it in one pass. The patch is cropped, not resized, which matters - more on that below.
The inputs and outputs that matter
Three inputs, all required:
patch(IMAGE) - the art you generated.frame(IMAGE) - the card/background that has the cutout.mask(MASK) - white marks the hole. This is the one to get right; if you feed an inverted mask, the "largest blob" becomes the frame's border and nothing pastes.
The single output is an IMAGE, ready to save or composite further.
How to install it
Same as its sibling node, because they ship together. In ComfyUI Manager search draw_tools, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Ky11le/ygo_tools
# restart ComfyUI
The README's git clone .../draw_tools line is stale (old repo name, 404s) - use ygo_tools. Dependency-wise it's just opencv-python>=4.5.0 on top of the torch/numpy you already have, no model files, and the nodes show up under the DrawTools category.
Common gotchas
- Generate your art at least as big as the hole. Because the node center-crops instead of scaling, a patch smaller than the hole leaves the cutout partially empty - transparent background showing through. Use Detect Inner Box to get the right size and don't undershoot.
- The output is RGBA, not plain RGB. The source always converts the frame to RGBA and composites with an alpha channel, so the result tensor is 4-channel. Save Image handles it fine, but a downstream node that assumes 3-channel RGB (some VAE/decode chains) may complain - if one does, that's why. This is normal and expected.
- White means hole, black means frame. Invert the polarity once and you'll paste your art over the border and leave the hole empty. If your mask came out of a node that inverts masks by convention, double-check it.
It's a small pack with a narrow job, and Paste Into Frame is the half that makes the finished card look assembled instead of photoshopped.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| patch | IMAGE | — | |
| frame | IMAGE | — | |
| mask | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |