百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-color-extractor

> 前端框架
开源

一个从图像中提取颜色的 React 组件

379 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个从图像中提取颜色的 React 组件

react-color-extractor

What

react-color-extractor is a React component that extracts colors from an image.

Motivation

This is one of the tools that I am using in creative coding. I was learning color theory and wanted a React based library to extract a collection of swatches from an image. The extracted colors then can be used to create interesting gradient patterns, loading designs with identical color scheme or crafting a symmetric color scheme across a system.

Use cases

  • Design systems

  • Creative coding

  • Creating advanced color tools

Install

bash
npm install react-color-extractor

or if you use yarn

bash
yarn add react-color-extractor

This package also depends on React, so make sure you've it installed.

Example

javascript
import React from 'react'
import { ColorExtractor } from 'react-color-extractor'

class App extends React.Component {
  state = { colors: [] }

  renderSwatches = () => {
    const { colors } = this.state

    return colors.map((color, id) => {
      return (
        

      
    )
  }
}

Checkout the demo on CodeSandbox

Examples

Check out the examples folder.

Usage

react-color-extractor can be used in two different ways.

  • With image element as children
javascript
 console.log(colors)}>
  

Check out this example.

  • Passing a local or remote image, or a blob url via src prop
javascript
"
  getColors={colors => console.log(colors)}
/>

Check out this example.

Using remote images

In development, make sure that you've configured proxy settings in your server config when you are using the remote images, otherwise you might run into CORS issue. You can also use this chrome extension to tackle CORS issue.

API

`` props

getColors

(colors: Array | string>) => void

getColors callback is invoked with an array of colors, either in hex or rgb format once the image is done processing. Use this callback to update the state with the colors array

javascript
 this.setState({ colors: colors })} />

rgb

type: boolean

When set to true, produces the color in rgb format. By default, colors produced are in hex format

javascript
 console.log(colors)} />

This will log colors in rgb format

onError

(error: Object) => void

onError callback is invoked if there is any issue with processing the image.

javascript
 this.setState({ hasError: true , msg: error })}>

src

type: string

src prop accepts a remote or local image url, or a blob url.

javascript
 console.log(colors)}
/>

maxColors

type: number

maxColors prop accepts a number for amount of colors in palette from which swatches will be generated.

javascript
 ...} maxColors={128} />

Contributing

If you like to contribute to this project, then follow the below instructions to setup the project locally on your machine.

bash
git clone https://github.com//react-color-extractor

cd react-color-extractor

yarn

Type checking

Run flow type checker using yarn flow

Building the source code

Run yarn build:component to build the source code.

TODO

  • Add quantizers

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcolorsconverterhexhsl

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架