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.
Command:
recolorjs --target '#00ff00'| Before | After |
|---|---|
![]() |
![]() |
git clone https://github.com/phpdave11/recolor.js.git
cd recolor.js
npm installnpx 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.
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 ~/.zshrcNow you can run:
recolor --target '#96a78f' --src ./icons --out ./outnpm testRun with verbose output:
npx jest --verboseOptional — only needed if you want compiled JS output in dist/:
npm run buildnpx eslint src/
npx tsc --noEmit
