All Projects β†’ nitin42 β†’ React Color Extractor

nitin42 / React Color Extractor

A React component which extracts colors from an image

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Color Extractor

Values.js
πŸ‡ Get the tints and shades of a color
Stars: ✭ 97 (-69.11%)
Mutual labels:  hex, rgb, hsl, colors
Gradstop
JavaScript micro library to generate gradient color stops πŸ³οΈβ€πŸŒˆ
Stars: ✭ 144 (-54.14%)
Mutual labels:  hex, rgb, hsl, colors
colors-convert
🦚 A simple colors library
Stars: ✭ 15 (-95.22%)
Mutual labels:  hex, colors, hsl, rgb
Tints And Shades
🌈 Display tints and shades of a given hex color in 10% increments.
Stars: ✭ 228 (-27.39%)
Mutual labels:  hex, rgb, colors
Farge
🎈Tell the name of hex color
Stars: ✭ 23 (-92.68%)
Mutual labels:  hex, hsl, rgb
ColorMinePortable
ColorMinePortable
Stars: ✭ 37 (-88.22%)
Mutual labels:  hex, hsl, rgb
Alfred-Colors-workflow
hex <=> rgb <=> hsl
Stars: ✭ 28 (-91.08%)
Mutual labels:  hex, hsl, rgb
go-rainbow
Golang Helper for beautiful CLI Applications
Stars: ✭ 86 (-72.61%)
Mutual labels:  hex, colors, rgb
Color.js
Extract colors from an image (0.75 KB) 🎨
Stars: ✭ 42 (-86.62%)
Mutual labels:  image, rgb, colors
color
A library of well-tested helper methods for working with colors.
Stars: ✭ 13 (-95.86%)
Mutual labels:  hex, hsl, rgb
colorsys.rs
Lib for modifying colors and converting to other spaces
Stars: ✭ 28 (-91.08%)
Mutual labels:  hex, hsl, rgb
Colorhighlight
🎨 Lightweight Color Highlight colorizer for Sublime Text
Stars: ✭ 76 (-75.8%)
Mutual labels:  hex, rgb, hsl
vscode-color
Helper with GUI to generate color codes such as CSS color notations.
Stars: ✭ 88 (-71.97%)
Mutual labels:  hex, hsl, rgb
ColorPicker
Customizable Color Picker control for WPF
Stars: ✭ 57 (-81.85%)
Mutual labels:  colors, hsl, rgb
Sorted Colors
A tool to sort the named CSS colors in a way that it shows related colors together
Stars: ✭ 167 (-46.82%)
Mutual labels:  rgb, hsl, colors
khroma
A collection of functions for manipulating CSS colors, inspired by SASS.
Stars: ✭ 28 (-91.08%)
Mutual labels:  hex, hsl, rgb
ColorHelper
No description or website provided.
Stars: ✭ 34 (-89.17%)
Mutual labels:  hex, hsl, rgb
Culori
A comprehensive color library for JavaScript.
Stars: ✭ 271 (-13.69%)
Mutual labels:  hex, rgb, hsl
color-converter
Command line tool for converting colors from RGB to HEX and vice versa.
Stars: ✭ 17 (-94.59%)
Mutual labels:  converter, rgb
hex-rgba
Convert HEX to RGBA
Stars: ✭ 12 (-96.18%)
Mutual labels:  hex, colors

react-color-extractor

size version

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

npm install react-color-extractor

or if you use yarn

yarn add react-color-extractor

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

Example

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 (
        <div
          key={id}
          style={{
            backgroundColor: color,
            width: 100,
            height: 100
          }}
        />
      )
    })
  }

  getColors = colors =>
    this.setState(state => ({ colors: [...state.colors, ...colors] }))

  render() {
    return (
      <div>
        <ColorExtractor getColors={this.getColors}>
          <img
            src="https://i.imgur.com/OCyjHNF.jpg"
            style={{ width: 700, height: 500 }}
          />
        </ColorExtractor>
        <div
          style={{
            marginTop: 20,
            display: 'flex',
            justifyContent: 'center'
          }}
        >
          {this.renderSwatches()}
        </div>
      </div>
    )
  }
}

Checkout the demo on CodeSandbox

Edit k3wj33kzw3

Examples

Check out the examples folder.

Usage

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

  • With image element as children
<ColorExtractor getColors={colors => console.log(colors)}>
  <img src="..." alt="..." style={{...}} />
</ColorExtractor>

Check out this example.

  • Passing a local or remote image, or a blob url via src prop
<ColorExtractor
  src="<local-or-remote-image-url-or-blob-url>"
  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

<ColorExtractor /> props

getColors

(colors: Array<Array<number> | 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

<ColorExtractor getColors={colors => 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

<ColorExtractor rgb getColors={colors => 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.

<ColorExtractor onError={error => this.setState({ hasError: true , msg: error })}>

src

type: string

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

<ColorExtractor
  src="https://i.imgur.com/OCyjHNF.jpg"
  getColors={colors => console.log(colors)}
/>

maxColors

type: number

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

<ColorExtractor src="..." getColors={colors => ...} maxColors={128} />

Contributing

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

git clone https://github.com/<your_username_here>/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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].