A library to process images and extract dominant color and palette.
You can install the library via npm or yarn:
npm install @babidi/pix
or
yarn add @babidi/pix
Here's an example of how you can use @babidi/pix
to extract the predominant color and palette from an image:
import Pix from '@babidi/pix';
import * as fs from 'fs';
const imageBuffer = fs.promises.readFile('path_to_your_image.jpg');
const image = new Pix(imageBuffer, Pix.Format.JPG);
console.log('Dominant Color:', image.dominant.toHex());
console.log('Palette:', image.palette.toHex());
Replace 'path_to_your_image.jpg'
with the path to the image file you want to process.
A benchmark was conducted comparing the performance of @babidi/pix
with another popular library called ColorThief in extracting the dominant color and color palette from different types of image files. Times are shown in milliseconds (ms).
File Type | Pix (ms) | ColorThief (ms) |
---|---|---|
PNG | 274 | 2325 |
JPEG | 309 | 3781 |
GIF | 262 | 237 |
BMP | 122 | No Supported |
WEBP | 726 | No Supported |
This project is licensed under the MIT License - see the LICENSE file for details.
For bug reporting and feature requests, please use the issues section of the repository.