# background remover (`ainz/background-remover`) Actor

Ai powered background remover, fast with high quality

- **URL**: https://apify.com/ainz/background-remover.md
- **Developed by:** [Elmehdi felaouss](https://apify.com/ainz) (community)
- **Categories:** AI, Automation, Developer tools
- **Stats:** 39 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $7.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Background Removal

AI-powered background removal tool that automatically removes backgrounds from images and allows you to apply custom backgrounds. Built with the high-quality BriaAI model for professional results.

### Why use Background Removal?

- **Professional Quality**: Uses AI for precise, clean background removal
- **Custom Backgrounds**: Add solid colors or upload custom background images
- **Multiple Formats**: Output in PNG, JPG, JPEG, or WebP formats
- **Batch Processing**: Handle multiple images efficiently
- **No Technical Skills Required**: Simple upload and process workflow
- **API Integration**: Easy integration into your existing workflows

### How it works

1. This actor accepts image uploads or URLs from the input
2. Uses advanced AI model to precisely identify and remove backgrounds
3. Optionally applies custom background colors or images
4. Processes the image according to your format and quality preferences
5. Stores the result for immediate download or API access

### Input Parameters

#### Required

- **Image**: Upload an image file or provide a URL to process

#### Background Options

- **Background Color**: Apply solid colors using hex (#FFFFFF), RGB (rgb(255,255,255)), or color names (white, black, red, etc.)
- **Background Image**: Upload a custom background image to composite behind your subject

#### Output Settings

- **Output Format**: Choose PNG, JPG, JPEG, or WebP
- **Maximum Resolution**: Control output size (512-4096 pixels)
- **Compression Options**: Adjust quality and compression settings
- **Preserve Transparency**: Keep original transparency from PNG images

### Sample Output

Here is sample output showing the transformation:

**Input**: Product photo with cluttered background\
**Output**: Clean product image with white background, perfect for e-commerce

```json
{
  "processedImage": "image url",
  "processingMetadata": "metadata url"
}
```

When verbose output is enabled, you get detailed processing information:

```json
{
  "originalSize": 2048576,
  "processedSize": 1536432,
  "format": "png",
  "width": 1920,
  "height": 1080,
  "processingTimeMs": 3250,
  "url": "image url"
}
```

### Use Cases

- **E-commerce**: Product photos with clean white backgrounds
- **Social Media**: Profile pictures and content creation
- **Marketing**: Professional headshots and promotional materials
- **Design**: Logo extraction and graphic workflows
- **Real Estate**: Property photos with custom backgrounds
- **Fashion**: Model photography and clothing catalogs

### Supported Input Formats

- **Image Types**: JPG, JPEG, PNG, WebP, GIF, BMP, TIFF
- **Input Sources**: File upload, HTTP/HTTPS URLs, Base64 encoded data
- **Resolution**: Up to 4096×4096 pixels

### Example Configurations

#### Basic Background Removal

```json
{
  "Image": "https://example.com/product.jpg",
  "outputFormat": "png"
}
```

#### White Background for E-commerce

```json
{
  "Image": "https://example.com/product.jpg", 
  "backgroundColor": "white",
  "outputFormat": "jpg",
  "compressionOptions": {
    "quality": 95
  }
}
```

#### Custom Background Image

```json
{
  "Image": "https://example.com/portrait.jpg",
  "backgroundImage": "https://example.com/studio-background.jpg",
  "outputFormat": "webp",
  "verboseOutput": true
}
```

### API Integration

#### Using Apify Client

```javascript
const ApifyClient = require('apify-client');
const client = new ApifyClient({ token: 'your-token' });

const run = await client.actor('ainz/background-remover').call({
  Image: 'https://example.com/image.jpg',
  backgroundColor: '#FFFFFF',
  outputFormat: 'jpg'
});

// Get the processed image
const kvStore = await client.keyValueStore(run.defaultKeyValueStoreId);
const imageBuffer = await kvStore.getRecord('OUTPUT');
```

# Actor input Schema

## `Image` (type: `string`):

Upload an image to process

## `maxResolution` (type: `integer`):

Maximum resolution for the output image (in pixels)

## `preserveTransparency` (type: `boolean`):

Keep transparent areas from the original image (useful for images that already have transparent elements)

## `backgroundColor` (type: `string`):

Background color for the processed image. Can be a hex color (#FFFFFF), RGB (rgb(255,255,255)), or color name (white). Leave empty for transparent background.

## `backgroundImage` (type: `string`):

Upload a background image to composite behind the processed image. This will override backgroundColor if provided.

## `outputFormat` (type: `string`):

Format for the output image

## `compressionOptions` (type: `object`):

Configure compression settings for the output image

## `verboseOutput` (type: `boolean`):

Include detailed processing information in the response

## Actor input object example

```json
{
  "maxResolution": 2048,
  "preserveTransparency": false,
  "backgroundColor": "",
  "outputFormat": "png",
  "verboseOutput": false
}
```

# Actor output Schema

## `processedImage` (type: `string`):

The image with background removed and optional custom background applied

## `processingMetadata` (type: `string`):

Detailed processing information including file sizes, dimensions, and processing time (only available when verbose output is enabled)

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("ainz/background-remover").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("ainz/background-remover").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call ainz/background-remover --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ainz/background-remover"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/jVbnv0PncZ2D6E8AJ/builds/kaqM1KXTEkaJ1kqh9/openapi.json
