[Script] Export sprite's layers separately

Export Layers

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.

Download

You can download my scripts from here: GitHub - PKGaspi/AsepriteScripts: My collection of Aseprite Scripts.

Installation

  1. Download or clone the repository.
  2. In Aseprite, go to File → Scripts → Open Scripts Folder.
  3. Copy the content of this repository’s script folder into the opened script
    folder.
  4. In Aseprite, go to File → Scripts → Re-scan Scripts Folder.

Changelog

  • v2.0 - Added name formatting, different file formats and a scale export factor.
  • v1.3 - Fixed layers in groups not exporting after API v1.2.14 changes.
  • v1.2 - Improved file name with sprites with multiple frames.
  • v1.1 - Added Windows support and an error message if no sprite is currently active.
  • v1.0 - Initial release.

I hope you find this script useful and thank you very much for using my script!
Any comment, feedback or suggestion is appreciated!

19 Likes

Hi @Gaspi, thanks for sharing and welcome to Aseprite community! :smiley:

I’ve added this script to the list of scripts I’m collecting here , I hope you don’t mind :slight_smile:

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).

3 Likes

Hi, @JJHaggar!

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.

Have a nice day!

2 Likes

That’s great, thank you very much! :smiley:

1 Like

you rock :heart:

2 Likes

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?

2 Likes

this is awesome!! thank you so much

2 Likes

Thank you so much!

You are my favorite person today. :3 Thank you so much!

1 Like

This is almost exactly what I am looking for but is there anyway to change the scale of layers its exporting?

I did try to edit the script myself but I did not really know what I was doing and its keeps running out of memory.

1 Like

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.

1 Like

Thank you very much for the Script I needed this, it would be great if you added the option to resize

Hello everyone!

Today I bring you a much awaited update to this script. You can get it along my other scripts here: GitHub - PKGaspi/AsepriteScripts: My collection of Aseprite Scripts

It includes many new options, including resize and naming formatting. I hope you all enjoy. I’m open to feedback here and in the repo’s issues.

1 Like

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.

This is awesome and incredibly helpful for a project that I’m working on! I really appreciate it.

非常感谢!我在为自己的游戏项目写一个导出图片和数据的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.

Can anyone help me? I keep getting this whenever I tried to use these scripts.

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.

1 Like

This usually happens when you incorrectly save the script file. Make sure you save the raw file, and not the web page that the file is displayed on.

1 Like

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.