replace-color icon indicating copy to clipboard operation
replace-color copied to clipboard

Multiple Color replacement

Open jeroldangarcia opened this issue 4 years ago • 3 comments

Is possible to replace 2 or more colors ?

jeroldangarcia avatar May 22 '21 08:05 jeroldangarcia

No

whalemare avatar Jul 08 '21 02:07 whalemare

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.

incutonez avatar Nov 24 '21 04:11 incutonez

https://github.com/if4lcon/replace-multiple-colors

BSN4 avatar Feb 11 '22 10:02 BSN4