Nodes/Krea 2 AnyPaint/Krea2 AnyPaint Prepare
ComfyUI Node

Krea2 AnyPaint Prepare

Lay out the canvas before Krea 2 repaints anything

By alexw5702-afk·Created about a month ago·Updated about a month ago· 34
Krea2 AnyPaint Prepare
  • source
  • generated_mask
  • semantic_reference
  • known_image
  • generated_mask
  • keep_mask
  • canvas_width
  • canvas_height
left0
top0
right512
bottom0
reference_max_edge384
boundary_redraw_px32

AnyPaint gives Krea 2 Turbo arbitrary-mask inpainting, outpainting, and mixed edits. But a LoRA can't read your mind about where the canvas ends and what's allowed to change. Krea2AnyPaintPrepare is the node that turns your source image, mask, and padding numbers into the actual geometry everything else in this pack keys off.

Here's the mental model: you feed it the source, an optional mask, and four padding values. White mask pixels and every padded pixel are generated; black pixels are preserved. That's the whole contract, and it's the ComfyUI mask convention - white means "make something new here", black means "leave this alone". The output of Load Image's Mask Editor connects straight into generated_mask, no conversion needed.

What it actually builds

Inside, the node places your source un-resized into a padded canvas and pads it up to a 16px alignment. Three things come out of that:

  • known_image - the full-resolution canvas with your source composited in. The empty padding isn't black or noise; it's filled with the source's median color, so the model gets a neutral backdrop instead of being asked to hallucinate everything from zero.
  • semantic_reference - a downscaled version of the same canvas (default max edge 384px) where the to-be-generated areas are filled with the median of the preserved pixels. This is the picture both the VAE reference and the Qwen3-VL text encoder actually look at, so it's what gives the model global coherence: it sees the whole scene, not just the mask.
  • generated_mask and keep_mask - the pair that controls sampling. generated_mask marks what gets repainted; keep_mask is the inverse, the pixels that must survive.

Then the canvas_width / canvas_height ints round it out, in case you want to preview or inspect the grid.

The inputs a beginner actually sets

  • left / top / right / bottom - padding on each side. Notice right defaults to 512: out of the box this node outpaints to the right. For pure inpainting set all four to zero.
  • reference_max_edge - the resolution of the semantic reference, 128–768 in steps of 16. 384 is the tuned default; bump it if fine structure in the source isn't being respected, keep it low if you're VRAM-strapped.
  • boundary_redraw_px - the seam band. The keep mask is dilated by this many pixels, meaning a band around your mask also gets redrawn so the new content blends into the old instead of leaving a hard line. Default 32 is sane; 0 gives you crisp-but-visible seams.

Installing it

This is one of three nodes in the alexw5702-afk/krea2-anypaint pack, so you install the whole thing once:

cd ComfyUI/custom_nodes
git clone https://github.com/alexw5702-afk/krea2-anypaint

Restart ComfyUI, then drop krea2_anypaint_rank32.safetensors from the HuggingFace repo into ComfyUI/models/loras. ComfyUI Manager users can just search "Krea 2 AnyPaint". The pack itself is tiny - no custom sampler, no extra pip deps beyond what ComfyUI already ships - but it assumes a current ComfyUI with native Krea 2 support, plus the usual three model files: the Krea 2 diffusion model (krea2_turbo_int8_convrot.safetensors), the Qwen3-VL text encoder, and the Qwen-Image VAE.

Gotchas

The node raises "the generated mask has no white pixels" if you feed it an all-black mask - it needs at least one pixel to generate, which is fair. Padding is always generated, so don't use padding as a cheap way to add a border you want preserved; that's what black mask pixels are for. And if your outpaint comes out looking like it was pasted on, check boundary_redraw_px before you blame the LoRA - too small a seam band is the classic cause of a visible edge.

From here, wire semantic_reference, known_image, and keep_mask into Krea2AnyPaintEncode, which is where the whole thing becomes a latent.

CategoryKrea2/AnyPaint

Inputs (8)

NameTypeDefaultDescription
sourceIMAGE
leftINT00–8192
topINT00–8192
rightINT5120–8192
bottomINT00–8192
reference_max_edgeINT384128–768
boundary_redraw_pxINT320–256
generated_maskoptMASK

Outputs (6)

NameTypeDescription
semantic_referenceIMAGE
known_imageIMAGE
generated_maskMASK
keep_maskMASK
canvas_widthINT
canvas_heightINT