Skip to content
Sign in
Image studioBackground removerMenu

Background removerPro

The cutout a matting model made, on a transparency checkerboard, with Keep and Remove brushes to fix its edges, edge softness, background swatches, hold to compare, and a PNG export at the image's natural size.

ProThe matte arrives with progress and the background fades away. Brush the edges with Keep and Remove, hold Compare, then export the PNG.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/background-remover

Usage

tsx
import { BackgroundRemover } from "@/components/ui/chatcn/pro/background-remover"

<BackgroundRemover
  src={image.url}
  alt={image.alt}
  width={image.width}
  height={image.height}
  mask={job.matteUrl}
  processing={job.status === "running"}
  progress={job.progress}
  onExport={(blob) => upload(blob)}
/>

mask is the matte the model returns: an alpha or black and white PNG, a canvas, ImageData or a vector path. Refinement strokes are stored as vectors in fractions of the image, so the export at the natural size is as sharp as the preview. Without onExport, Export downloads the PNG; the ref's toBlob() gives you the same file for your own flow. Swatches take any CSS color or token and resolve it before export.

Examples

States

ProRemoving with progress, refined edges on white, no subject found, a failed removal, disabled and a broken image.

Props

PropTypeNotes
src, altstringThe canvas is named "Cutout of <alt>"
width, height, aspectRationumberFrame shape before load and the export size
maskMaskSourceThe matte from the model
processing, progressboolean, numberA status chip after 300 ms, with real progress when you have it
error, onRetryboolean | string, () => voidA failed removal with Retry
tool, defaultTool, onToolChange"keep" | "remove"Default remove
size, defaultSize, onSizeChangenumberBrush diameter in px, 6 to 120
softness, defaultSoftness, onSoftnessChangenumberEdge softness in px, 0 to 16. Default 1
background, defaultBackground, onBackgroundChange, backgroundsstring, { value, label, color? }[]Default transparent, white and black
defaultStrokes, onStrokesChangeMaskStroke[]brush strokes keep, erase strokes remove
onExport, filename(blob) => void, stringDefault downloads "cutout.png"
ref{ toBlob, undo, redo, reset }For your own export flow
disabled, toolbar, footerLock, hide the toolbar, a slot below

Keyboard

KeyAction
K or B, R or EKeep, remove
[, ]Smaller or larger brush by 4 px; with Shift, by 16 px
Hold \See the original
⌘Z or Ctrl+ZUndo the last stroke
⇧⌘Z, Ctrl+YRedo
Delete on the canvasReset the edges to the model's cutout

Accessibility

  • The canvas is a focusable group named after the image, with a described hint for the brushes and keys. Compare is a button you hold with the pointer, Space or Enter.
  • Brushing needs a pointer; everything else is a labeled control. Size and edge are sliders that announce pixels, the swatches are a toggle group named by color.
  • Strokes, undo, reset and export are announced politely. Processing is a status with its progress.
  • Under forced colors the brush ring hides and the swatches keep a system outline.

Motion

  • When the matte arrives, the original fades out over 280 ms and leaves the cutout on the checkerboard.
  • Brushing draws straight onto the canvas with no easing; the ring follows the pointer with transforms only, and the removed area shows faintly while you brush.
  • Compare swaps instantly, since it is held from the keyboard. Status chips fade in 150 ms.