CLI for batch scaling

My goal is to scale many images and save them to the same filename. I could probably this with the Scripts, but I assume this could be also be done using theCommand Line Interface tool. I’m currently on a Mac and I’m able to run this:
/Applications/ -b something.png --scale 10 --save-as image-x10.png

This works! However, I would like it to loop over all the files in a folder. Ho

Also, right now I have to run CLI like this:
/Applications/ …
is there a way to run Aseprite without referencing the applications folder?

So this took a little bit of work but I have a Command Line script that works for me. I am on a Mac and I’m using OhMyZshell. So, you may need to find something that works for your setup.

  1. I created an alias that opens up Aseprite. This is setup in OhMyZShell within ~/.oh-my-zsh/custom/aliases.zsh I added this alias so I could run Aseprite anywhere:
    alias ase=’/Applications/’

  2. You can loop over all files in a directory by running:
    for FILE in *(.); do echo $FILE; done

  3. I took this and was able to run this:
    for item in *(.); do ase -b $item --scale 2 --save-as scaled/$item ; done

This will loop over all items in the folder and scale it by 2 (That can be changed). This saves all of those files to have the same name but puts them into the /scaled directory.

Hi there @dexter! :wave: Nice alternative about the alias to reference aseprite executable.

About the Bash script to scale several files, other option is creating a Lua script directly and calling:

aseprite -b -script-param scale=2 -script scale-all-files.lua

And then in scale-all-files.lua:

local dir = '.'
local fs = app.fs
local scale = tonumber(app.params["scale"])
if not scale or scale < 2 then return print "invalid scale" end

for _,filename in pairs(fs.listFiles(dir)) do
  local ext = fs.fileExtension(filename)
  local outputExt = ext -- output extension in case you want to convert to other format

  if ext == "aseprite" then
    local fullFilename = fs.joinPath(dir, filename)
    local sprite =
      .. "/scaled/"
      .. fs.fileTitle(fullFilename)
      .. "-x" .. tostring(scale) .. "." .. outputExt)

Hey @dacap!
Thanks for the suggestion. I may be doing something wrong, I was wondering if you can point me in the right direction. I created the file scale-all-files.lua inside the /Aseprite/scripts folder. I did a “Rescan” of the scripts folder. The script shows up in the list of scripts.

From Terminal I opened up the directory with all of my files I want to scale. I attempted to run the command: aseprite -b -script-param scale=2 -script scale-all-files.lua
I keep getting the error: Error executing script scale-all-files.lua

I also attempted to open up all of the files inside the Aseprite app thinking the batch might need those to be currently open. Unfortunately that isn’t working either. Any thoughts on what I might be missing?

I would also love to know how to use that script :slight_smile:

I pretty much did all the steps you did, but if I use the command in cmd (also with aseprite.exe, instead of just aseprite) I don’t get any response :frowning: