0.0.9 • Published 4 years ago

use-image-color v0.0.9

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

useImageColor

Grab color palette from any image using this hook

Example

How does it work?

It renders your image on a canvas and then generates its palette of colors using color quantization.

Includes Image Component

This image component renders a placeholder color while your original images are loading.

Before loading big images (color from smaller images) Before loading

After loading big images: After loading

Live Sandbox demo:

Live Sandbox Demo npm.io

How does this image component work?

You must provide src (your original image) and a thumbnail (smaller image). As soon as the thumbnail is loaded the skeleton becomes visible using its dominant color. In the meantime, your original image continues loading, finally, when your original image arrives, it replaces the skeleton.

Installation:

npm install use-image-color

The hook:

Usage:

import useImageColor from 'use-image-color'

export function Card() {
  const { colors } = useImageColor(url, { cors: true, colors: 5 })
  return (...);
}

Hook params:

useImageColor(url: String, options: OptionsObject)
paramdescriptiondefault
corsUse CORS. Enable this if you are using external imagesfalse
colorsNumber of colors to grab5
formatOutput format: rgb or hexhex
windowSizeSize of window to grab pixels, low values are faster50

The component:

Usage:

import { Image } from 'use-image-color'

export function Card() {
  return (
    <Image src={url} thumbnail={thumbnail} />
  );
}

Component params:

paramdescriptionrequired
thumbnailSmall version of your imagetrue
srcOriginal version of your imagetrue
wrapperStyleStyle object to apply to the wrapper of the image and the colorfalse
wrapperClassClass to apply to the wrapper of the image and the colorfalse
0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago