Registry / ai-ml / node-vibrant

node-vibrant

JSON →
library4.0.4jsnpmunverified

node-vibrant is a JavaScript library engineered for extracting prominent colors and generating a color palette from images. It effectively analyzes image data to produce a set of 'swatches,' including vibrant, muted, dark vibrant, light vibrant, dark muted, and light muted colors. The library is currently at stable version 4.0.4 and has resumed active development following a substantial four-year hiatus before the significant 4.0.0 release. Key features include comprehensive support for both Node.js and browser environments, a full rewrite in TypeScript since version 3.0.0-alpha.1, and a modern Promise-based API for handling asynchronous operations. This combination makes it a robust solution for applications requiring dynamic, type-safe color palette generation from images, integrating smoothly with contemporary JavaScript development workflows.

npm install node-vibrant
INSTALL
IMPORT
SIG · NODE-VIBRANT
N
node-vibrant
ai-mljavascriptv4.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Vibrant
import { Vibrant } from 'node-vibrant/node';
import Vibrant from 'node-vibrant';
Since v4.0.0, the `Vibrant` class is a named export, and you must import from environment-specific paths like `node-vibrant/node` or `node-vibrant/browser`.
Vibrant (Browser)
import { Vibrant } from 'node-vibrant/browser';
import Vibrant from 'node-vibrant';
For browser environments, use the explicit import path `node-vibrant/browser` since v4.0.0.
Vibrant (CommonJS pre-v4)
const Vibrant = require('node-vibrant');
import { Vibrant } from 'node-vibrant';
Prior to v4.0.0, `Vibrant` was typically a default export and could be imported via CommonJS `require()` directly from the package root. This pattern is deprecated for v4+.

Demonstrates how to extract a color palette from an image URL using the Promise-based API in a Node.js environment, displaying the dominant color swatches.

import { Vibrant } from 'node-vibrant/node'; // Or 'node-vibrant/browser' for browsers async function extractColorsFromImage(imageUrl: string) { try { console.log(`Extracting colors from: ${imageUrl}`); const palette = await Vibrant.from(imageUrl).getPalette(); console.log('Generated Color Palette:'); console.log(' Vibrant:', palette.Vibrant?.hex || 'N/A'); console.log(' Muted:', palette.Muted?.hex || 'N/A'); console.log(' Dark Vibrant:', palette.DarkVibrant?.hex || 'N/A'); console.log(' Light Vibrant:', palette.LightVibrant?.hex || 'N/A'); console.log(' Dark Muted:', palette.DarkMuted?.hex || 'N/A'); console.log(' Light Muted:', palette.LightMuted?.hex || 'N/A'); if (palette.Vibrant) { console.log(` Vibrant RGB: ${palette.Vibrant.rgb}`); console.log(` Vibrant Population: ${palette.Vibrant.population}`); } } catch (error) { console.error('Failed to extract colors:', error); } } // Example usage with a public image URL // For a local file in Node.js, replace 'imageUrl' with a local path like 'file:///path/to/image.jpg' const exampleImageUrl = 'https://picsum.photos/id/1018/1000/600'; extractColorsFromImage(exampleImageUrl);
Debug
Known issues
breakingStarting with v4.0.0, the `Vibrant` class is no longer a default export but a named export. Code relying on `import Vibrant from 'node-vibrant'` will break.
fix
Change your import statement to `import { Vibrant } from 'node-vibrant/node;'` or `import { Vibrant } from 'node-vibrant/browser;'` depending on your environment.
affects: >=4.0.0
breakingVersion 4.0.0 introduced mandatory environment-specific imports. You must now import from `node-vibrant/node` for Node.js, `node-vibrant/browser` for browsers, or `node-vibrant/worker` for Web Workers.
fix
Update your import paths to explicitly target your environment, e.g., `import { Vibrant } from 'node-vibrant/node;'`.
affects: >=4.0.0
breakingNode.js v18+ is now required for `node-vibrant` versions 4.0.0 and above. Environments running older Node.js versions will encounter compatibility issues.
fix
Upgrade your Node.js environment to version 18 or higher.
affects: >=4.0.0
breakingThe API was rewritten to be Promise-based in v3.0.0-alpha.1. Code using callbacks will need to be refactored to use `async/await` or `.then().catch()` patterns.
fix
Refactor your asynchronous operations to use Promises, for example: `Vibrant.from(imageUrl).getPalette().then(palette => ...);` or `const palette = await Vibrant.from(imageUrl).getPalette();`
affects: >=3.0.0-alpha.1
gotchaThe `Builder.getSwatches` alias was removed in v4.0.0; developers should use `Builder.getPalette` instead.
fix
Replace calls to `getSwatches()` with `getPalette()`.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: (0 , node_vibrant_node__WEBPACK_IMPORTED_MODULE_0__.Vibrant) is not a constructor
Attempting to use `Vibrant` as a default import or without destructuring when it's a named export.
fix
Ensure you are using `import { Vibrant } from 'node-vibrant/node';` (or `/browser`) and then `Vibrant.from(...)`.
Error: Cannot find module 'node-vibrant'
Incorrect import path for v4.0.0+ in a Node.js or browser environment, or attempting to use the root import for environment-specific functionality.
fix
For v4.0.0 and later, specify the environment in the import path: `import { Vibrant } from 'node-vibrant/node';` or `import { Vibrant } from 'node-vibrant/browser';`
TypeError: Vibrant.from(...).getPalette is not a function (or similar async errors)
This error often occurs when the `getPalette()` method is called without awaiting the result of `Vibrant.from()`, or if not properly handling the Promise-based API.
fix
Ensure you are `await`ing the `getPalette()` call within an `async` function or chaining a `.then()` callback: `await Vibrant.from(imageUrl).getPalette();` or `Vibrant.from(imageUrl).getPalette().then(...)`.
Upgrade
Version history
4.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources