Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-color-extractor

> 前端框架
Open source

A React component which extracts colors from an image

379 stars0 likes1 views
WebsiteGitHub

About

A React component which extracts colors from an image

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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptcolorsconverterhexhsl

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

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