color-thief-ts
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Color Thief

Grab the color palette from an image using just Javascript.Works in the browser & node.

Getting Started

install

yarn add color-thief-ts

or

npm install color-thief-ts

example for browser

import ColorThief from "color-thief-ts";

const colorThief = new ColorThief();
const dominantColor = await colorThief.getColorAsync("your-domaon/your-image-url.jpg");
const palette = await colorThief.getPaletteAsync("your-domaon/your-image-url.jpg", 5);

console.log(dominantColor);
console.log(palette);

example for node.js

import ColorThief from "color-thief-ts/node";
import fetch from "node-fetch";
import Sharp from "sharp";

const colorThief = new ColorThief();

const image = await fetch("http://localhost:3000/images/example.png")
  .then((res) => res.arrayBuffer())
  .then((arrayBuffer) => Buffer.from(arrayBuffer));

const palette1 = await colorThief.getPalette(
  { type: "image/png", buffer: image },
  5
);

const palette2 = await colorThief.getPalette(
  "http://localhost:3000/images/example.png",
  5
);

const palette3 = await colorThief.getPalette(
  "./images/example.png",
  5
);

const color = await colorThief.getColor(
  { type: "image/png", buffer: image }
);

Package Sidebar

Install

npm i color-thief-ts

Weekly Downloads

90

Version

1.1.1

License

MIT

Unpacked Size

40.5 kB

Total Files

10

Last publish

Collaborators

  • hoowong