项目介绍

Vibrant-Colors/node-vibrant 是一个托管在 GitHub 上的开源项目,主要使用 TypeScript 编写,目前获得 2.5k 个 Star、113 次 Fork。

仓库全名
Vibrant-Colors/node-vibrant
Star 数
2.5k
Fork 数
113
未关闭 Issue
21

README 摘要

node-vibrant Extract prominent colors from an image. Identical API for node.js, browser, and worker environments Install Usage Worker Usage Quantization is the most time-consuming stage in node-vibrant. Luckily, the quantization can be run in the WebWorker to avoid freezing the UI thread. Here's how to use this feature: This requires your bundler to handle ?worker transforms similar to how Vite does Documentation…

完整内容见 GitHub 原始 README 或本页 。

常见问题

node-vibrant 用什么语言开发?

主要使用 TypeScript 编写,目前有 2.5k 个 Star。

如何获取 node-vibrant 的源码?

可以直接克隆仓库:git clone https://github.com/Vibrant-Colors/node-vibrant.git,默认分支为 main;安装与运行步骤见仓库 README。

node-vibrant 最近还在维护吗?

仓库最近一次更新为 1月28日,当前有 21 个未关闭 Issue;Star 数为 2.5k,可作为社区活跃度的参考。

简要分析

热度分
2693
价值分
1507
活跃状态
活跃

语言占比

Astro
CSS
JavaScript
MDX
TypeScript

Release

README

node-vibrant

Join the discussion on Github Best of JS

Extract prominent colors from an image.

  • Identical API for node.js, browser, and worker environments

Install

$ npm install node-vibrant

Usage

// Node
import { Vibrant } from "node-vibrant/node";
// Browser
import { Vibrant } from "node-vibrant/browser";
// Web Worker
import { Vibrant } from "node-vibrant/worker";

// Using builder
Vibrant.from("path/to/image")
	.getPalette()
	.then((palette) => console.log(palette));

// Using constructor
let v = new Vibrant("path/to/image", opts);
v.getPalette().then((palette) => console.log(palette));

Worker Usage

Quantization is the most time-consuming stage in node-vibrant. Luckily, the quantization can be run in the WebWorker to avoid freezing the UI thread.

Here’s how to use this feature:

import { Vibrant, WorkerPipeline } from "node-vibrant/worker";
import PipelineWorker from "node-vibrant/worker.worker?worker";

Vibrant.use(new WorkerPipeline(PipelineWorker as never));

This requires your bundler to handle ?worker transforms similar to how Vite does

Documentation

Docs can be seen currently in the docs folder. It includes reference docs and step-by-step guides.

We also have a few examples that you can reference for your needs.

PRs welcomed to expand either of these!

Notes

Result Consistency

The results are consistent within each user’s browser instance regardless of the visible region or display size of an image, unlike the original vibrant.js implementation.

However, due to the nature of the HTML5 canvas element, image rendering is platform/machine-dependent. The resulting swatches may vary between browsers, Node.js versions, and between machines. See Canvas Fingerprinting.

The test specs use CIE delta E 1994 color difference to measure inconsistencies across platforms. It compares the generated color on Node.js, Chrome, Firefox, and IE11. At quality == 1 (no downsampling) with no filters and the results are rather consistent. Color diffs between browsers are mostly not perceptible by the human eye. Downsampling will cause perceptible inconsistent results across browsers due to differences in canvas implementations.

评论

暂无评论