# Color Palette Extractor (`web.harvester/color-palette-extractor`) Actor

Extract dominant colors from images using K-means clustering. Get color palettes in HEX, RGB, and HSL formats with color names and percentages.

- **URL**: https://apify.com/web.harvester/color-palette-extractor.md
- **Developed by:** [Web Harvester](https://apify.com/web.harvester) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 4 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$3.00/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period.You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#rental-actors

## 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

## Color Palette Extractor

> 🎨 Extract dominant colors from images using K-means clustering

[![Apify Actor](https://img.shields.io/badge/Apify-Actor-blue)](https://apify.com)

### What This Actor Does

- **Extract dominant colors** - Find the most prominent colors in any image
- **Multiple formats** - Output in HEX, RGB, and HSL color formats
- **Color names** - Get human-readable color names (e.g., "Navy Blue", "Forest Green")
- **Customizable** - Control number of colors, quality, and filtering options
- **Batch processing** - Analyze multiple images at once

### Use Cases

| Use Case | Description |
|----------|-------------|
| **Brand Analysis** | Extract brand colors from logos and marketing materials |
| **Design Inspiration** | Generate color palettes from photos and artwork |
| **E-commerce** | Categorize products by color |
| **Content Moderation** | Detect dominant colors in user-uploaded images |
| **Data Visualization** | Create color schemes based on image themes |

### Input Examples

#### Basic Usage

```json
{
    "imageUrls": ["https://example.com/image.jpg"],
    "colorCount": 5
}
```

#### High Quality Analysis

```json
{
    "imageUrls": ["https://example.com/image.jpg"],
    "colorCount": 8,
    "quality": "accurate",
    "includeColorNames": true
}
```

#### Exclude Neutrals

```json
{
    "imageUrls": ["https://example.com/image.jpg"],
    "colorCount": 5,
    "excludeWhite": true,
    "excludeBlack": true,
    "minSaturation": 0.2
}
```

### Configuration

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `imageUrls` | array | - | URLs to images (required) |
| `colorCount` | integer | 5 | Number of colors to extract (1-20) |
| `quality` | string | "balanced" | fast, balanced, or accurate |
| `excludeWhite` | boolean | false | Exclude near-white colors |
| `excludeBlack` | boolean | false | Exclude near-black colors |
| `minSaturation` | number | 0 | Minimum saturation (0-1) |
| `outputFormats` | array | \["hex","rgb","hsl"] | Color formats to include |
| `includeColorNames` | boolean | true | Include color names |

### Output

```json
{
    "source": "https://example.com/starry-night.jpg",
    "success": true,
    "colorCount": 5,
    "dominantColor": "#1a3a5c",
    "palette": [
        {
            "percentage": 35.2,
            "hex": "#1a3a5c",
            "rgb": { "r": 26, "g": 58, "b": 92 },
            "hsl": { "h": 211, "s": 56, "l": 23 },
            "name": "Dark Slate Blue"
        },
        {
            "percentage": 22.8,
            "hex": "#f4d03f",
            "rgb": { "r": 244, "g": 208, "b": 63 },
            "hsl": { "h": 48, "s": 89, "l": 60 },
            "name": "Gold"
        }
    ]
}
```

### Quality Settings

| Quality | Resize To | Speed | Accuracy |
|---------|-----------|-------|----------|
| **fast** | 100px | Fastest | Good |
| **balanced** | 200px | Medium | Better |
| **accurate** | 400px | Slower | Best |

### Color Formats

| Format | Example |
|--------|---------|
| **HEX** | `#1a3a5c` |
| **RGB** | `{ "r": 26, "g": 58, "b": 92 }` |
| **HSL** | `{ "h": 211, "s": 56, "l": 23 }` |

### Cost Estimation

| Scale | Images | Compute Units |
|-------|--------|---------------|
| Small | 10 | ~0.001 |
| Medium | 100 | ~0.01 |
| Large | 1000 | ~0.05 |

### Technical Details

- **Language:** Python 3.12
- **Libraries:** Pillow, scikit-learn, webcolors
- **Algorithm:** K-means clustering
- **Memory:** 256MB-512MB

### Supported Image Formats

- JPEG / JPG
- PNG
- GIF
- WebP
- BMP
- TIFF

***

**Keywords:** color, palette, extract, dominant, kmeans, image, design, hex, rgb, hsl

# Actor input Schema

## `imageUrls` (type: `array`):

URLs to images to analyze

## `colorCount` (type: `integer`):

Number of dominant colors to extract

## `quality` (type: `string`):

Higher quality = more accurate but slower

## `excludeWhite` (type: `boolean`):

Exclude near-white colors from results

## `excludeBlack` (type: `boolean`):

Exclude near-black colors from results

## `minSaturation` (type: `number`):

Minimum color saturation (0-1). Higher values exclude grays.

## `outputFormats` (type: `array`):

Color formats to include in output

## `includeColorNames` (type: `boolean`):

Include approximate color names (e.g., 'Navy Blue', 'Forest Green')

## Actor input object example

```json
{
  "imageUrls": [
    "https://picsum.photos/800/600"
  ],
  "colorCount": 5,
  "quality": "balanced",
  "excludeWhite": false,
  "excludeBlack": false,
  "minSaturation": 0,
  "outputFormats": [
    "hex",
    "rgb",
    "hsl"
  ],
  "includeColorNames": true
}
```

# 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 = {
    "imageUrls": [
        "https://picsum.photos/800/600"
    ],
    "outputFormats": [
        "hex",
        "rgb",
        "hsl"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("web.harvester/color-palette-extractor").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 = {
    "imageUrls": ["https://picsum.photos/800/600"],
    "outputFormats": [
        "hex",
        "rgb",
        "hsl",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("web.harvester/color-palette-extractor").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "imageUrls": [
    "https://picsum.photos/800/600"
  ],
  "outputFormats": [
    "hex",
    "rgb",
    "hsl"
  ]
}' |
apify call web.harvester/color-palette-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=web.harvester/color-palette-extractor",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

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