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/Aseprite.app/Contents/MacOS/aseprite -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/Aseprite.app/Contents/MacOS/aseprite …
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.
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/Aseprite.app/Contents/MacOS/aseprite’
You can loop over all files in a directory by running:
for FILE in *(.); do echo $FILE; done
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.
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 = app.open(fullFilename)
sprite:resize(sprite.width*scale,
sprite.height*scale)
sprite:saveCopyAs(
fs.filePath(fullFilename)
.. "/scaled/"
.. fs.fileTitle(fullFilename)
.. "-x" .. tostring(scale) .. "." .. outputExt)
end
end
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?