Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Color replacement #15

Open
jeroldangarcia opened this issue May 22, 2021 · 3 comments
Open

Multiple Color replacement #15

jeroldangarcia opened this issue May 22, 2021 · 3 comments

Comments

@jeroldangarcia
Copy link

Is possible to replace 2 or more colors ?

@whalemare
Copy link

No

@incutonez
Copy link

It definitely is, but it takes some finagling and can potentially cause issues. A simple replacement could look like this:

const targetColors = ['#FF0000', '#00FF00'];
const replaceColors = ['#0000FF', '#FF0000'];
let data = '/path/to/initial/image.png';
for (let i = 0; i < replaceColors.length; i++) {
  data = await replaceColor({
    image: data,
    colors: {
      type: "hex",
      targetColor: targetColors[i],
      replaceColor: replaceColors[i]
    }
  });
}

The problem becomes when you're replacing one color early on that could potentially be replaced further down in the process, like if my first replaceColors was '#00FF00', it would get replaced by '#FF0000' in the next pass. You can come up with some priority system, but it gets a little more difficult with different shades of colors.

@BSN4
Copy link

BSN4 commented Feb 11, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants