Change Canvas size programatically

I need to add some padding to an image programmatically, and thought about using the app.command.CanvasSize command to that end, but didn’t find any docs about its parameters.

I’m trying to call the method in a similar fashion to how SpriteResize works, with the ui parameter set to false, but it’s always showing the gui anyway.

As a workaround, I’m using SpriteResize to resize the entire thing (canvas plus the actual sprite), and then override de sprite with a copy of the original one, positioned at the center.

What would be the correct way of using app.command.CanvasSize?

3 Likes

I need this too, I want to resize canvas automatically but I can’t seem to change it’s parameters. Btw, you can see what parameters it’s using here: aseprite/src/app/commands/cmd_canvas_size.cpp at main · aseprite/aseprite · GitHub
I just started scripting Aseprite today, so I’m not sure if I’m missing something.
I tried this but it doesn’t work:

app.command.CanvasSize
{
ui=false,
left=0,
rigth=w,
top=0,
bottom=h,
trimOutside=false
}

2 Likes

From what I can see there isn’t a ui parameter.

Looking at the above link it states:
struct CanvasSizeParams : public NewParams {
Param left { this, 0, “left” };
Param right { this, 0, “right” };
Param top { this, 0, “top” };
Param bottom { this, 0, “bottom” };
Param trimOutside { this, false, “trimOutside” };
};
So far I have:
app.command.CanvasSize{ left = 0, right = 0, top = 64, bottom = 0, trimOutside = false }

But this code doesn’t work when I run it as it just brings up the GUI.

Gonna try the Alvarez technique with SpriteResize.

I’ll try to fix this for the next release (probably v1.2.22 with some other bug fixes)

3 Likes

Is it possible to do this now via CLI?
I would really love to have the ability :slight_smile: