An easy and fast way of exporting every layer of a sprite into individual sprites.
Introduction and description
Hi!
I’m working on a game where characters are drawn in layers, so you can choose their clothes and complements. As I was making these sprites I started to miss a function to export all layers on a sprite as individual png images with their own name and on a specific folder. I couldn’t find this feature, so I investigated and found that there is an api for Aseprite, so I made my own script that does just that before making sure there was no way to do it other way.
Usage
Have your sprite with multiple layers you want to be exported individually. Execute the script and your layers will export in separate files. Hidden layers are also exported.
Options
Output directory: The folder where to export. Note that you will specify a
file, not a folder. This is because Aseprite’s API doesn’t support folder
selection.
File name: The name of every exported file. The possible formatters are:
– {spritename}: The name of the sprite to export.
– {layername}: The name of the layer.
– {layergroups}: The groups the layer is into.
Group separator: The character used to separate the group names in file name.
Export format: File format of exported files.
Export scale: The scale at which to export. The resolution of the file will
be multiplied by this number. Useful for media sharing.
Save sprite: If checked, the full sprite will be saved in the output
directory.
Examples
With default options:
A layer with name layer1 will be exported as layer1.png.
A layer with name layer2 inside a group with name group1 will be exported
as group1/layer2.png.
A layer with name layer3 inside a group with name group2, which is inside group1, will be exported as group1/group2/layer3.png.
Hi @Gaspi, thanks for sharing and welcome to Aseprite community!
I’ve added this script to the list of scripts I’m collecting here , I hope you don’t mind
Is there any possibility that you add support for Windows to the script? (maybe asking about the OS in the code to choose one way of using paths or another? I’m a bit noob so I’m not sure if that can be done easily in lua).
Thank you very much for the wellcome! I updated the script and it now works both on Linux and Windows. The way I did os recognition is not the best but it should be fine.
great tool! It’s almost exactly what I was looking for. Say would it be difficult to modify the script to save frames from each layer in a separate folder and have the folder named after the layer?
Hi! I’m planning to update the script to add more functionalities. For now, you can resize the sprite manually before running the script, and resize back after exporting.
Hello! Thank you for making this awesome script, but would it be possible to add an option to exclude layers from the exporting. I was thinking of hiding the layers or even appending the layer name with an underscore or something.
EDIT: I’ve made changes to the script that will skip the export on layers that are prefixed with a given character. The default prefix is an asterisk (*). I can make a pull request on the git repo when I have time and you can add it in for others if you want.
非常感谢!我在为自己的游戏项目写一个导出图片和数据的lua脚本工具。但我对app.command.ExportSpriteSheet这个接口的使用方式不清楚,官方文档写的也不够详细。参考了你的lua脚本后,我成功的解决了我的问题。
Thank you very much! I’m writing a Lua scripting tool for exporting images and data for my game project. But I am not clear about the use of app.command.ExportSpriteSheet, the official document writing is not detailed enough. After referring to your Lua script, I successfully solved my problem.
Hi. To me it looks like the script file (export_layers.lua) has been modified and no longer has correct lua syntax. I would sugest to reinstall using the latest version and try again.
I’m unfamiliar with Github, I’ve tried using the Raw button and save the January version from there, but it still have the same error. Can you please explain to me how to download these scripts properly? Thank you for your time and sorry to bother like this.