-
Notifications
You must be signed in to change notification settings - Fork 0
/
Export Tags.lua
45 lines (39 loc) · 1.58 KB
/
Export Tags.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
----------------------------------------------------------------------------------------------------
-- Exports the defined tags of the sprite as individual image files according to the supplied root
-- directory and the export directory specified in the user data of each tag.
----------------------------------------------------------------------------------------------------
--
-- Get a handle to the current sprite.
--
local spr = app.activeSprite
if not spr then
return app.alert("There is no active sprite.")
end
--
-- Ask the user where the root directory that they would like tags to be exported to resides.
--
local dlg = Dialog("Export Tags")
dlg:entry{ id="directory", label="Output Directory", focus=true }
dlg:slider{ id="scale", label="Scale", min=1, max=10, value=2 }
:button{ id="ok", text="&Export"}
:button{ text="&Cancel" }
:show()
if not dlg.data.ok then
return end
--
-- Export each tagged frame as its own PNG file according to its name. Tag names can specify
-- sub-directories to the export directory using slashes (e.g. "subdirectory/name") if desired.
--
-- NOTE: Currently, we only support exporting single-frame tags and PNG files. In the future, we
-- might add support for exporting multi-frame tags (either as sprite strips or as GIF files).
--
for i, tag in ipairs(spr.tags) do
local img = Image(spr.width, spr.height)
img:drawSprite(spr, tag.fromFrame.frameNumber, 0)
img:resize(spr.width * dlg.data.scale, spr.height * dlg.data.scale)
img:saveAs(dlg.data.directory .. "/" .. tag.name .. ".png")
end
--
-- Make sure the UI and state update.
--
app.refresh()