Skip to content

Instantly share code, notes, and snippets.

@dacap
Created June 9, 2021 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacap/9df368ba276a45048dc85f96b23ea818 to your computer and use it in GitHub Desktop.
Save dacap/9df368ba276a45048dc85f96b23ea818 to your computer and use it in GitHub Desktop.
Export tileset
if TilesetMode == nil then return app.alert "Use Aseprite v1.3" end
local lay = app.activeLayer
if not lay.isTilemap then return app.alert "No active tilemap layer" end
local tileset = lay.tileset
local dlg = Dialog("Export Tileset")
dlg:file{ id="file", label="Export to File:", save=true, focus=true,
filename=app.fs.joinPath(app.fs.filePath(lay.sprite.filename),
lay.name .. ".png") }
:label{ label="# Tiles", text=tostring(#tileset) }
:separator()
:button{ text="&Export", focus=true, id="ok" }
:button{ text="&Cancel" }
:show()
local data = dlg.data
if data.ok then
local spec = lay.sprite.spec
local grid = tileset.grid
local size = grid.tileSize
spec.width = size.width
spec.height = size.height * #tileset
local image = Image(spec)
image:clear()
for i = 0,#tileset-1 do
local tile = tileset:getTile(i)
image:drawImage(tile, 0, i*size.height)
end
image:saveAs(data.file)
-- Open exported file?
--app.open(data.file)
end
@lua-rocks
Copy link

Useful script, thanks! But it exports images with indexed colors as black-white.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment