image-remove-background
Image Remove Background
Removes the background from an image, leaving only the foreground subject with transparency.
Command
npx agent-media@latest image remove-background --in <path> [options]
Inputs
| Option | Required | Description |
|---|---|---|
--in |
Yes | Input file path or URL |
--out |
No | Output path, filename or directory (default: ./) |
--provider |
No | Provider to use (local, fal, replicate) |
--resolution |
No | Output resolution (e.g., "2048x2048"). Supported by fal Dynamic model. |
Output
Returns a JSON object with the processed image path:
{
"ok": true,
"media_type": "image",
"action": "remove-background",
"provider": "fal",
"output_path": "nobg_123_abc.png",
"mime": "image/png",
"bytes": 34567
}
Examples
Remove background from local file:
npx agent-media@latest image remove-background --in portrait.jpg
Remove background using specific provider:
npx agent-media@latest image remove-background --in portrait.jpg --provider replicate
Remove background at full resolution (fal Dynamic model):
npx agent-media@latest image remove-background --in portrait.jpg --provider fal --resolution 2048x2048
Providers
local
Runs locally on CPU using Transformers.js, no API key required.
- Uses
Xenova/modnetmodel - Models downloaded on first use (~25MB)
- You may see a
mutex lock failederror — ignore it, the output is correct if"ok": true
npx agent-media@latest image remove-background --in portrait.jpg --provider local
fal
- Requires
FAL_API_KEY - Uses
birefnet/v2model withGeneral Use (Dynamic)variant - Supports
--resolutionoption (e.g., "2048x2048") for processing at full input resolution
replicate
- Requires
REPLICATE_API_TOKEN - Uses
birefnetmodel
More from agntswrm/agent-media
audio-transcribe
Transcribes audio to text with timestamps and optional speaker identification. Use when you need to convert speech to text, create subtitles, transcribe meetings, or process voice recordings.
131image-crop
Crops an image to specified dimensions around a focal point. Use when you need to extract a portion of an image, create thumbnails with custom positioning, or prepare images for specific aspect ratios.
83image-generate
Generates an image from a text prompt using AI models. Use when you need to create images from descriptions, generate artwork, or produce visual content from text.
78video-generate
Generates video from text prompts or animates static images. Use when you need to create videos from descriptions, animate images, or produce video content using AI.
64image-edit
Edits an existing image using a text prompt. Use when you need to modify, enhance, or transform an image based on text instructions.
62image-resize
Resizes an image to specified dimensions. Use when you need to change image size, create thumbnails, or prepare images for specific display requirements.
49