Set Margin Extra
Save your trim margins into image metadata so the crop survives the save
- extras
- margin
- extras
Set Margin Extra stores a margin bundle - top, right, bottom, left - into the pack's metadata extras. It's the persistence half of a two-node trick built around the pack's trim-margin workflow, and understanding the trick tells you why this node exists at all.
The workflow: the pack's Aspect Ratio to Size (Trim Margin) computes a sampling size that's larger than the final image you want, then Trim Image by Margin crops the margins afterward. Why sample bigger than needed? Because diffusion models are happier producing away from the image edges - it's the classic "generate with headroom, crop the borders" trick, and it gives you clean final edges instead of the mushy artifacts models paint along borders. The margin bundle (four edge values) is what connects the "size with margins" step to the "crop the margins" step.
The problem this node solves: margins are a recipe, and if you save the trimmed result and reload it, the margins are gone - you'd have to remember them to reproduce the workflow. Set Margin Extra writes the margin bundle into the metadata, and the matching Get Margin Extra restores both the bundled margin and its four edge values on load. Save, reload, and the trim recipe is intact.
Inputs and outputs
- key - the parameter line key for the stored margin.
- margin (optional) - the
IPT-Marginbundle (top/right/bottom/left) to serialize. Wire this fromAspect Ratio to Size (Trim Margin)so the stored margins are exactly what the graph cropped. Leave it disconnected and the entry is empty. - extras (optional) - the incoming extras bundle to merge into.
Output is the merged extras bundle, chainable with the other Set nodes and consumable by Image Info Context.
Why the margins need to travel as a unit
The four edge values aren't independent - they're a linked set that only makes sense together (the trim node needs all four to know how to crop, and the size-with-margin node produces them as a pair-linked bundle where horizontal/vertical pairs total either zero or the unit step). Flattening them into four separate number extras would work mechanically but lose the "this is one margin configuration" meaning. Storing the whole IPT-Margin under one key keeps the recipe atomic - store it as a unit, restore it as a unit.
Install
Standard pack install:
cd ComfyUI/custom_nodes
git clone https://github.com/kinorax/comfyui-info-prompt-toolkit.git
cd comfyui-info-prompt-toolkit
pip install -r requirements.txt
Or ComfyUI Manager → search "ComfyUI-Info-Prompt-Toolkit" → install → restart. No models, no extra dependencies.
Where people get burned
Margins are only meaningful relative to the sampled size - a 32px margin on a 1024-wide image is a different crop than 32px on a 2048-wide one. If your workflow recomputes size after reload instead of trusting the stored size, store the size too (Set Size Extra) so the margin and the canvas stay consistent. And the usual extras rules apply: a pack saver must write the file, duplicate keys overwrite, and if Trim Image by Margin never runs because the margin socket is unconnected, your saved margins are a record of intent, not of what was cropped.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| key | STRING | Parameter line key | |
| extrasopt | IPT-ImageInfoExtras | — | |
| marginopt | IPT-Margin | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| extras | IPT-ImageInfoExtras | — |