npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

change-image-color

v1.0.1

Published

NPM package with CLI to change colors in image

Downloads

31

Readme

change-image-color

Manipulate the colors in image.

Installation

// npm
npm install change-image-color

// yarn
yarn add change-image-color

Usage

const ChangeColor = require('change-image-color');

// with a callback
ChangeColor({ /* your configuration */ }, (err, res) => {
    if (err) {
        /* error handling */
    } else {
        processResult(res);
    }
})

// as a Promise
ChangeColor({ /* your configuration */ })
    .then(res => {
        processResult(res);
    })
    .catch(err => {
        /* error handling */
    })

result is an array containing the Jimp instance of the image and its source. Check jimp to see what you can do with the instance.

const processResult = (res) => {
    res.map(({ src, image }) => {
        // src: your image source
        // image: Jimp instance

        /* your function */
    })
}

Options

This repo uses jimp to modify the color. You may want to check more with Jimp.

| name | type | required | default | description | | --- | --- | --- | --- | --- | | src | string \| Buffer \| Object | true | -- | Source of images | | colors | Object | true | -- | Colors to be modified | | deltaE | number | false | 2.3 | Color difference ΔE | | formula | "76" \| "94" \| "00" | false | 00 | Color difference formula | | transparency | boolean | false | true | Match color with the same transparency | | recursive | boolean | false | false | Search directory recursively |

options.src

options.src accepts many anything that is a valid input in Jimp.read(src) (Usage): path to a file, URL, a Jimp instance or a buffer.

Files are processed one by one to prevent a sudden drain in CPU and memory

// local file
ChangeColor({ src: 'path/to/your/image.png' })

// URL
ChangeColor({ src: 'https://path/to/your/image.png' })

// Jimp instance
ChangeColor({ src: jimpInstance })

// buffer
ChangeColor({ src: buffer })

To process multiple images, you can specify path of a directory. Or even an array of the accepted input.

// local directory
ChangeColor({ src: 'path/to/your/directory' })

// an array
ChangeColor({
    src: [
        'path/to/your/directory',
        'https://path/to/your/image.png',
        buffer,
    ]
})

options.colors

options.colors can be set in different formats.

// in array of object
ChangeColor({
    colors: [{
        from: from_color1,
        to: to_color1,
    }, {
        from: from_color2,
        to: to_color2,
    }]
})

// in object
ChangeColor({
    colors: {
        from_color1: to_color1,
        from_color2: to_color2,
    }
})

A valid color could be a string or object that is valid as a input in colord. For more detail, please check Colord.

Plugins of names, cmyk, hwb, lab, lch, xyz are enabled.

color = '#333' // hex

color = 'rgba(33, 33, 22, 0.5)' // rgb string

color = { r: 33, g: 33, b: 33, a: 0.5 } // rgb object

// check `colord` for other expressions

options.deltaE

options.deltaE should be a number between 0 and 100. Colors with Delta E below 2 are hard for people to notice.

For more, check here.

options.formula

options.formula specify the formula to calculate Delta E. You can choose between CIE76, CIE94 and CIE00.

For more, check here.

options.transparency

Only the colors with Delta E smaller than options.deltaE AND identical transparency will be replaced.

To bypass transparency check, set options.transparency to false.

| color in image | color to match | options.transparency | result | | --- | --- | --- | --- | | #000000 | #000000 | true | Match | | #00000077 | #000000 | true | NOT Match | | #000000 | #00000077 | true | NOT Match | | #000000 | #00000077 | false | Match |

options.recursive

options.recursive only works when specify directory in options.src.

It will loop recursively in that directory to find all the images. However, it will ignore all the sub-directories with name node_modules, .git or .vscode.

Command Line

// installed globally
change-image-color

// installed locally
npx change-image-color

Run the script and answer the questions.

If the output file already exist, it will add a suffix -cic to the filename.

License

This project is licensed under the terms of the MIT license.

Support

If you find this repo useful, please share to your friends. Or you can buy me a coffee: