Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
batch replace/swap colors in PNG images
#2
Why script? If the images aren't too big, you can

  1. load all the images as pieces of a single layer (sprite-sheet like),
  2. do the color change on the layer,
  3. split the layer back to files.
I have a several scripts for this that support two worflows, one where you create & save the work layer directly from the image files,  and one where you create the work layers from individual layers (that you mass-load/save). So

1) is either File>Open as layers followed by ofn-layer-tiles (Layer>Tiles>Join tiles), or just ofn-tiles (File>Open tiles)

2) is either ofn-layer-tiles (Layer>Tiles>Split tiles ...) followed by ofn-export-layers (File>Export all layers), or ofn-tiles (File>Export tiles)  

Second point, unless this is pixel art, smooth lines are rendered with pixels where the color is a mix of the colors on either side, so you may have more than 10 colors and you have to wonder what happens for these intermediate colors.
  • If you really have only 10 colors, then a simple way to do it is to make the image color-indexed and edit the colors  in the palette (in which case you don't even need to create a work layer, the palette is the same for all layers).
  • Otherwise the right way to do it is to convert the replaced color to transparency (bucket-fill with that color in Color erase mode) and then fill the transparent pixels with the target color by bucket-filling in Behind mode. This can be done quickly using the replace-foreground-by-background script.
Reply


Messages In This Thread
RE: batch replace/swap colors in PNG images - by Ofnuts - 05-12-2019, 07:54 AM

Forum Jump: