Can anyone help me with what I'd expect to be a simple script?

Hi guys, sorry if this kind of post belongs somewhere else,
but I’ve run into a wall trying to automate a task for generating sprites for my game,
as I have no real experience with Lua scripting.
Essentially I just need to:

  • crop the canvas width of the original images (a series of animation frames) by 106 pixels on each side
  • despeckle the image with the default settings, 2 pixels width + 2 pixels height,
  • resize to 512 x 512 pixels

Can anyone help me out, or can point me in the right direction? I’ve been looking at the API
and tried writing it myself, but I have very little knowledge about how Lua works (I usually code in C#), and feel as if it’s a bit overkill to learn Lua just to automate a few built-in Aseprite tasks

hi, it’s less about learning lua and more about wrestling with api :expressionless:
however, it seems to me that you need this:

  1. crop sprite: app.command.CropSprite, but for that you need to make a selection, so maybe it would be better for you to use app.command.CanvasSize: api/CanvasSize.md at main · aseprite/api · GitHub
  2. despeckle: app.command.Despeckle: api/Despeckle.md at main · aseprite/api · GitHub
  3. resize: app.command.SpriteSize: api/SpriteSize.md at main · aseprite/api · GitHub
  4. and of course you might want to wrap it in app.transaction to create just one undo step: api/app.md at main · aseprite/api · GitHub

so… the script could be something like this:

app.transaction( function()

	app.command.CanvasSize {
	  ui=false,
	  left=-106,
	  top=-106,
	  right=-106,
	  bottom=-106, --bounds=Rectangle,
	  trimOutside=false
	}

	app.command.Despeckle {
	  ui=false,
	  channels=FilterChannels.RGB,
	  width=2,
	  height=2,
	  tiledMode=none,
	}

	app.command.SpriteSize {
	  ui=false,
	  width=512,
	  height=512,
	  --scale=1.0, scaleX=1.0, scaleY=1.0,
	  lockRatio=false,
	  method="nearest"
	}


end )


there’s only one caveat: at least one layer has to be selected, or the aseprite will throw out error. you can have multiple layers selected.

Thank you so much!
Looks quite simular to what I tried to write originally, so that’s good to know :grin:

2 Likes