color-sucker
v1.4.1
Published
Color Sucker is a Node.js script that extracts color palettes from images in a specified folder. It supports multiple image formats, including `.jpg`, `.jpeg`, `.png`, and `.gif`. For `.gif` files, it extracts frames, combines them into a single image, an
Downloads
10
Readme
Color Sucker
Color Sucker is a Node.js script that extracts color palettes from images in a specified folder. It supports multiple image formats, including .jpg, .jpeg, .png, and .gif. For .gif files, it extracts frames, combines them into a single image, and extracts the palette from the combined image.
Quick Start
Will extract color palettes from images in the current directory and save them to ./output/palettes.json:
npx color-suckername colors and convert them to multile formats:
npx color-sucker && npx palette-aldente ./output/palettes.json --formats name,rgb,hsl --namelist bestOf Features
- Extracts color palettes from images.
- Supports
.jpg,.jpeg,.png, and.gifformats. - Combines frames from
.giffiles into a single image for palette extraction. - Configurable via
sucker.config.js. - Parallel processing with configurable thread limits.
Installation
Clone the repository:
git clone <repository-url> cd color-suckerInstall dependencies:
npm install
Configuration
Edit the sucker.config.js file to customize the script:
imagesFolder: Path to the folder containing images (relative to the project root).outputFolder: Path to the folder where results will be saved (relative to the project root).outputJson: Filename for the JSON output containing extracted palettes (will be placed inoutputFolder).outputHtml: Filename for the HTML report (will be placed inoutputFolder). If defined, an HTML report will be generated.paletteSize: Number of colors to extract from each image.maxGifFrames: Maximum number of frames to extract from GIFs (set tonullfor all frames).maxThreads: Maximum number of threads for parallel processing.
Usage
There are two main ways to run Color Sucker:
1. Using npm (after cloning the repository)
If you have cloned the repository and installed dependencies:
npm startThis method uses the sucker.config.js file located within the cloned repository.
2. Using npx (recommended for quick use without cloning)
You can run Color Sucker directly in any directory using npx:
npx color-suckerTo specify the number of colors to extract, use the --colors or -c flag:
npx color-sucker --colors 10
# or
npx color-sucker -c 3To generate an HTML report showing the images and their extracted palettes, use the --report html flag:
npx color-sucker --report htmlYou can combine both flags:
npx color-sucker --colors 8 --report htmlThese flags will override the corresponding settings in any sucker.config.js or the default values.
Behavior with npx:
- With
sucker.config.js: If asucker.config.jsfile is present in the directory where you runnpx color-sucker, that configuration will be used (unless overridden by CLI flags like--colors). - Without
sucker.config.js: If nosucker.config.jsis found in the current directory:- The script will look for images in the current directory (
.orprocess.cwd()). - The output folder will be set to
./outputwithin the current directory. - The output files will be saved using the default filenames (
palettes.jsonandreport.htmlif HTML report generation is enabled). - Default values for
paletteSize,maxGifFrames, andmaxThreadsfrom the script's internal default configuration will be used.
- The script will look for images in the current directory (
This makes it easy to quickly extract palettes from images in any folder without needing to clone the repository or manage a global installation.
Dependencies
- Google Art Palette: Used for palette extraction.
- p-queue: Manages parallel processing with a thread pool.
- gif-frames: Extracts frames from GIF files.
- canvas: Combines GIF frames into a single image.
Output
The extracted palettes are saved in the JSON file specified in sucker.config.js (default: output/palettes.json). Each entry includes the image name and its extracted colors.
License
This project is licensed under the MIT License.
