Change the palette of several sprites

(Before using these scripts create a backup of your sprites)

A possible way to update the palette of several sprites automatically would be to create a Bash script that for each file uses a Lua script that converts the palette in the sprites.

Imagine that we have a set of sprites called player.aseprite, enemy.aseprite, etc. And a palette in global_palette.aseprite. We could create the following Bash script that for each .aseprite file calls a fix_palette.lua script:

# Adjust the $aseprite variable to the specific path of your platform
aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”
for file in *.aseprite ; do
  $aseprite -b -script-param file=$file -script fix_palette.lua
done

Then in the fix_palette.lua file:

-- Load the global palette
local palette = Palette{ fromFile='global_palette.aseprite' }
if not palette then
  print('there is no global_palette.aseprite')
  return 1
end

local sprite = app.open(app.params['file'])
if sprite then
  sprite:setPalette(palette)
  -- Or do other modifications in sprite.palettes[1]...

  -- Warning: we are overwriting the original file
  sprite:saveAs(sprite.filename)
end

More info about sprite.palettes, sprite:setPalette(), or Palette{}.

3 Likes