node-vibrant

repository·main·Indexed 25 days ago

https://github.com/vibrant-colors/node-vibrant

A library for extracting prominent colors from images, providing an identical API across Node.js, browser, and Web Worker environments. It identifies significant colors for use in UI themes and color palettes, offering specialized packages like @vibrant/generator-default, @vibrant/image-browser, @vibrant/image, and @vibrant/quantizer. The library includes utilities for color space conversion (RGB, HSL, CIELab, Hex) and perceptual difference calculations using CIE delta E 1994.

Tokens
17.5K
Snippets
59
Records
142
Agent score
78%

What's inside node-vibrant

  1. Explore @vibrant/color API surface

    main
    The @vibrant/color package provides the core primitives for color manipulation, representation, and comparison within the Vibrant ecosystem. It includes classes for color swatches, interfaces for palettes and filters, and a suite of utility functions for converting between different color spaces (RGB, HSL, XYZ, CIELab) and calculating color differences.
  2. Use @vibrant/image-browser for browser-based image color extraction

    main
    The @vibrant/image-browser package provides a browser-compatible implementation of the ImageClass. It is designed to be used in web environments where you need to extract vibrant colors from images using the node-vibrant API. This package implements the necessary image handling logic specifically for the browser runtime.
  3. Understand result consistency and platform dependencies

    main

    While node-vibrant provides consistent results within a single browser instance regardless of image display size, the underlying HTML5 canvas rendering is platform-dependent.

    Key considerations:

    • Platform Variance: Swatches may vary between different browsers, Node.js versions, and different machines due to how canvas is implemented.
    • Downsampling: Using downsampling can cause perceptible inconsistencies across browsers. For maximum consistency, use quality == 1 (no downsampling).
    • Human Perception: At quality == 1 with no filters, color differences between major browsers (Chrome, Firefox, IE11) are generally not perceptible to the human eye.
  4. Use the Builder class to configure Vibrant

    main

    The Builder class is a helper used to configure settings and create a Vibrant instance. It supports method chaining to set various parameters such as quality, color count, and filters before executing the color extraction. You can initiate a builder using Vibrant.from(src) or by calling new Builder(src, opts).

    Vibrant.from(src)
      .quality(1)
      .clearFilters()
      // ...
      .getPalette()
      .then((palette) => {})