Skip to content

phpdave11/recolor.js

Repository files navigation

recolor.js

Recolor PNG files with a hue shift. The tool detects the dominant chromatic colour in each PNG, then shifts every chromatic pixel to a target colour. Non-chromatic pixels (greys, whites, blacks) and transparency are preserved.

Example transformation

Command:

recolorjs --target '#00ff00'
Before After
Before recolor After recolor

Install

git clone https://github.com/phpdave11/recolor.js.git
cd recolor.js
npm install

Usage

npx tsx src/cli.ts --target '#96a78f' --src ./icons --out ./out
Flag Description Default
--target Target hex colour (required)
--src Source directory containing PNGs .
--out Output directory for recoloured PNGs out

After processing, each file's dominant colour is compared against the target. Files that match (distance < 30) are saved to --out. Mismatches are skipped and flagged in the output.

Shell Alias

Add to ~/.bash_profile or ~/.zshrc:

alias recolor='npx --prefix ~/code/phpdave11/recolor.js tsx ~/code/phpdave11/recolor.js/src/cli.ts'

Then reload your shell:

source ~/.bash_profile  # or source ~/.zshrc

Now you can run:

recolor --target '#96a78f' --src ./icons --out ./out

Tests

npm test

Run with verbose output:

npx jest --verbose

Build

Optional — only needed if you want compiled JS output in dist/:

npm run build

Lint

npx eslint src/
npx tsc --noEmit

About

Recolor PNG files with a hue shift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published