npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

auto-palette

v1.3.3

Published

Extract prominent color palette from your image automatically

Downloads

117

Readme

Auto Palette

Auto Palette is a library that automatically extracts a prominent color palette from your image.

NPM Version License GitHub Actions Codacy Codecov FOSSA

Features

Color palette extracted from an image using Auto Palette

[!NOTE] Photo by Pixabay from Pexels: https://www.pexels.com/photo/yellow-pink-and-violet-tulips-52508/

❯ Automatically extracts color palette from image ❯ Provides detailed color information color, name, position and population ❯ Supports multiple color extraction algorithms (dbscan, kmeans ) ❯ Supports multiple image sources (HTMLImageElement, HTMLCanvasElement, ImageData) ❯ Supports both Browser and Node.js ❯ Zero dependencies

Installation

Using npm:

$ npm install auto-palette

Using yarn:

$ yarn add auto-palette

Using pnpm:

$ pnpm add auto-palette

Usage

// ESM
import { Palette } from 'auto-palette';

// CJS
const { Palette } = require('auto-palette');

const palette = Palette.extract(image);
const swatches = palette.findSwatches(8, 'vivid');
for (const swatch of swatches) {
  console.log({
    name: swatch.name,              // The similar color name of the swatch
    color: swatch.color.toString(), // The color of the swatch
    position: swatch.position,      // The position of the swatch in the image
    population: swatch.population,  // The pixel count of the swatch
  });
}

Examples

| Source Image | Default | Vivid | Muted | |:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------:| | Yellow Pink and Violet Tulips | Default color palette | Vivid color palette | Muted color palette | | Closeup photo of doughnuts | Default color palette | Vivid color palette | Muted color palette | | Close-up Photo of Assorted Colored Chalks | Default color palette | Vivid color palette | Muted color palette |

API

For more detailed information, please refer to the documentations in the docs directory.

Palette

extract(image: ImageSource, options?: Options): Palette

Extracts a color palette from the given image source(HTMLImageElement, HTMLCanvasElement or ImageData).
It takes an image source and an optional Options object as parameters.

const options: Options = {
  algorithm: 'dbscan',
  samplingRate: 0.5,
  maxSwatches: 16,
  filters: [luminanceFilter(0.2, 0.8)],
};
const palette = Palette.extract(image, options);

The Options can include properties such as algorithm, samplingRate, maxSwatches, and filters.

interface Options {
  // The color extraction algorithm to use. Default is 'dbscan'.
  algorithm?: 'dbscan' | 'kmeans';
  // The sampling rate of the image. Default is 1.0.
  samplingRate?: number;
  // The maximum number of swatches to extract. Default is 256.
  maxSwatches?: number;
  // The color filters to apply. Default is [opacityFilter()].
  filters?: ColorFilter[];
}

findSwatches(n: number, theme?: Theme): Swatch[]

Finds the best n swatches in the palette.
The “best” swatches are determined based on their population and optionally a theme. The theme can be basic, vivid, muted, light or dark. Default is basic.

const swatches = palette.findSwatches(5, 'light');

Contributing

Contributions are welcome! For detailed information on how to contribute, please refer to the CONTRIBUTING guidelines.

License

This library is distributed under the MIT License.See the LICENSE.

FOSSA Status