node-vibrant
repository·main·Indexed 25 days ago
https://github.com/vibrant-colors/node-vibrantA 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.
What's inside node-vibrant
- node-vibrant is a library used to extract prominent colors from an image. It identifies the most significant colors present in an image, which can be used for UI themes, color palettes, or other visual applications.
Use @vibrant/image-browser for browser-based image processing
mainThe@vibrant/image-browserpackage provides the necessary tools to process images within a browser environment. The primary interface for this package is theBrowserImageclass, which handles image loading and color extraction in the browser.Use the @vibrant/generator-default package
mainThe@vibrant/generator-defaultpackage provides a default implementation of a color generator within thenode-vibrantecosystem. It includes theDefaultGeneratorfunction, aDefaultOptsvariable for standard configuration, and theGeneratorOptionsinterface for defining custom generation parameters.Explore @vibrant/color API surface
mainThe@vibrant/colorpackage 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.Use @vibrant/generator-default to generate original vibrant palettes
main@vibrant/generator-default is the default generator implementation used to produce the original vibrant color palette from an image. It is designed to work within thenode-vibrantecosystem to identify and extract dominant colors.Use @vibrant/image-browser for browser-based image color extraction
mainThe@vibrant/image-browserpackage provides a browser-compatible implementation of theImageClass. It is designed to be used in web environments where you need to extract vibrant colors from images using thenode-vibrantAPI. This package implements the necessary image handling logic specifically for the browser runtime.Use @vibrant/quantizer for custom quantizer development
main@vibrant/quantizer provides helper utilities and TypeScript definitions for developers who want to implement their own custom quantizer logic within thenode-vibrantecosystem. It is designed to assist in writing the algorithms that reduce an image's color palette to a specific set of representative colors.Use @vibrant/image for ImageClass helpers and typings
mainThe@vibrant/imagepackage provides helper functions and TypeScript definitions designed to assist developers in implementing or working with anImageClass. This is intended for use when building custom image processing logic within thenode-vibrantecosystem.Use @vibrant/image-node for Node.js image processing
mainThe@vibrant/image-nodepackage provides Node.js-specific implementations for image processing within the Vibrant ecosystem. It is primarily used via theNodeImageclass to handle image data in a Node.js environment.Understand result consistency and platform dependencies
mainWhile
node-vibrantprovides 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 == 1with no filters, color differences between major browsers (Chrome, Firefox, IE11) are generally not perceptible to the human eye.
Use the Builder class to configure Vibrant
mainThe
Builderclass is a helper used to configure settings and create aVibrantinstance. 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 usingVibrant.from(src)or by callingnew Builder(src, opts).Vibrant.from(src) .quality(1) .clearFilters() // ... .getPalette() .then((palette) => {})Understand the Resolvable<T> type alias
mainThe
Resolvable<T>type alias is a utility type used throughout the library to indicate that a value can be either a direct instance of typeTor aPromisethat resolves to typeT. This allows APIs to support both synchronous and asynchronous inputs or outputs seamlessly.type Resolvable<T> = T | Promise<T>;