登录 注册

color-thief

去点 Star
自动化与工作流
13,667
Stars
1,308
Forks
162
Watchers
0
Open Issues
MIT
许可证
TypeScript
语言
2011-11-01
创建时间
2026-08-03
最近更新

项目能做什么

纯 JavaScript 实现的图像调色板提取工具,支持浏览器和 Node.js 环境。
来源:AI 基于仓库事实生成 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# Color Thief

> Extract dominant colors and palettes from images in the browser and Node.js.

[![npm version](https://img.shields.io/npm/v/colorthief)](https://www.npmjs.com/package/colorthief)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/colorthief)](https://bundlephobia.com/package/colorthief)
[![types](https://img.shields.io/npm/types/colorthief)](https://www.npmjs.com/package/colorthief)

## Install

```bash
npm install colorthief
```

Or load directly from a CDN:

```html
<script src="https://unpkg.com/colorthief@3/dist/umd/color-thief.global.js"></script>
```

## Quick Start

```js
import { getColorSync, getPaletteSync, getSwatches } from 'colorthief';

// Dominant color
const color = getColorSync(img);
color.hex();      // '#e84393'
color.css();      // 'rgb(232, 67, 147)'
color.isDark;     // false
color.textColor;  // '#000000'

// Palette
const palette = getPaletteSync(img, { colorCount: 6 });
palette.forEach(c => console.log(c.hex()));

// Semantic swatches (Vibrant, Muted, DarkVibrant, etc.)
const swatches = await getSwatches(img);
swatches.Vibrant?.color.hex();
```

## Features

- **TypeScript** — full type definitions included
- **Browser + Node.js** — same API, both platforms
- **Sync & async** — synchronous browser API, async for Node.js
- **Live extraction** — `observe()` watches video, canvas, or img elements and emits palette updates reactively
- **Worker friendly** — runs inside your own Web Worker via `ImageBitmap` or `OffscreenCanvas`
- **Progressive extraction** — 3-pass refinement for instant rough results
- **OKLCH quantization** — perceptually uniform palettes via `colorSpace: 'oklch'`
- **Semantic swatches** — Vibrant, Muted, DarkVibrant, DarkMuted, LightVibrant, LightMuted
- **Rich Color objects** — `.hex()`, `.rgb()`, `.hsl()`, `.oklch()`, `.css()`, contrast ratios, text color recommendations
- **WCAG contrast** — `color.contrast.white`, `color.contrast.black`, `color.contrast.foreground`
- **AbortSignal** — cancel in-flight extractions
- **CLI** — `colorthief photo.jpg` with JSON, CSS, and ANSI output
- **Zero runtime dependencies**

## API at a Glance

| Function | Description |
|---|---|
| `getColorSync(source, options?)` | Dominant color (sync, browser only) |
| `getPaletteSync(source, options?)` | Color palette (sync, browser only) |
| `getSwatchesSync(source, options?)` | Semantic swatches (sync, browser only) |
| `getColor(source, options?)` | Dominant color (async, browser + Node.js) |
| `getPalette(source, options?)` | Color palette (async, browser + Node.js) |
| `getSwatches(source, options?)` | Semantic swatches (async, browser + Node.js) |
| `getPaletteProgressive(source, options?)` | 3-pass progressive palette (async generator) |
| `observe(source, options)` | Watch a source and emit palette updates (browser only) |
| `createColor(r, g, b, population)` | Build a Color object from RGB values |

### Options

| Option | Default | Description |
|---|---|---|
| `colorCount` | `10` | Number o
阅读完整原文

商业机会分析 AI 生成

基于图像自适应的 UI 主题与壁纸配色 Figma 插件

产品构想利用其语义色块(Vibrant、Muted 等)与 WCAG 对比度检测功能,开发一款为 Figma 设计师提供‘从海报/封面一键生成可访问性 UI 组件配色规范’的工具。
核心功能一键提取画布图片主色系、自动输出符合 WCAG 规范的暗黑/明亮主题色板、直接绑定 Figma Variables / Design Tokens。
目标用户UI/UX 设计师、品牌视觉设计师。
难度/周期低 · 2-3 周 · 成本:极低(主要是 Figma 插件开发者账号与轻量维护)
收费模式免费基础功能 + 增值功能(高级变量导出、多图批量处理)采用月度/年度订阅(推测)。
竞争风险Figma 生态内同类色板提取插件竞争激烈;壁垒较低容易被替代。
依据 已验证事实

高可用图像色板与无障碍分析 Cloud API / Microservice

产品构想针对电商、媒体资产库等需要批量提取图片主色、打上色彩标签及计算可读背景色的场景,提供云端托管高并发 API 及 SDK。
核心功能高并发图片色板提取、CDN 边缘计算节点适配、OKLCH/P3 色域支持、直接返回可读前景色推荐及对比度报告、批量异步任务队列。
目标用户中小企业研发团队、内容管理系统(CMS)运营方、电商图片审核团队。
难度/周期中等 · 1-2 个月 · 成本:轻量云服务器/Serverless 资源费、带宽成本
收费模式按 API 调用量计费(Freemium,超额阶梯收费)。
竞争风险由于该库本身体积小且零依赖,技术能力较强的团队往往选择直接自行在内网集成 Node 版而非购买外部 API。
依据 数据支持的判断

自适应媒体卡片与动态背景前端 SDK(商业授权/专业组件版)

产品构想包装类似于 Spotify/Apple Music 的动态背景过渡与高对比度文字排版效果,提供现成且经过跨浏览器性能优化的 React/Vue/WebComponent 商业 UI 组件套件。
核心功能视频/Canvas 实时色调抽取 (`observe()` 封装)、平滑色彩过渡动效、自动选择黑色/白色安全文本、OffscreenCanvas/Worker 性能加速封装。
目标用户前端开发者、独立开发者、媒体流播放网站与 App 创作者。
难度/周期低 · 3-4 周 · 成本:开发环境与演示站点域名服务器成本
收费模式双重许可(开源个人版 + 商业闭源应用买断/订阅授权)或 UI Kit 模板销售。
竞争风险前端技术社区对通用样式组件付费意愿有限,需高度打磨交互动效与视觉表现力才具备商业吸引力(推测)。
依据 AI推测
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

项目中文简介Stars语言
fengsp/color-thief-py 中文介绍暂未生成
Grabs the dominant color or a representative color palette f
1,109 Python
ksubileau/color-thief-php 中文介绍暂未生成
Grabs the dominant color or a representative color palette f
639 PHP
yamoridon/ColorThiefSwift 中文介绍暂未生成
Grabs the dominant color or a representative color palette f
286 Swift
SvenWoltmann/color-thief-java 中文介绍暂未生成
Grabs the dominant color or a representative color palette f
238 Java
KSemenenko/ColorThief 中文介绍暂未生成
Color Thief for .NET
175 C#
nate-xyz/paleta 中文介绍暂未生成
Extract the dominant colors from any image.
136 Rust
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。

项目优势与风险

技术成熟度创建于 2011-11-01,最近推送 2026-08-03,发布过 21 个 Release
社区活跃Star 13,667 / Fork 1,308 / Issue 0(数据支持,可自行核实)
许可证MIT
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

快速开始(以仓库 README 为准)
git clone https://github.com/lokesh/color-thief.git
cd color-thief
# 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
阅读原仓库文档
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。