local spr = app.activeSprite
if not spr then
return app.alert("请先打开一个 .aseprite 文件")
end
-- 获取导出路径
local outputPath = spr.filename:gsub("[^/\\]+$", "") .. "layers_exported/"
app.fs.makeDirectory(outputPath)
-- 递归处理所有图层,包括组内图层
local function exportVisibleImageLayers(layerList)
for _, layer in ipairs(layerList) do
if layer.isGroup then
-- 递归组内图层
exportVisibleImageLayers(layer.layers)
elseif layer.isImage and layer.isVisible then
local cel = layer:cel(1)
if cel and cel.image then
local image = Image(cel.image)
local bounds = image.bounds
if not image:isEmpty() then
-- 创建临时 Sprite 用于导出
local tempSprite = Sprite(image.width, image.height, spr.colorMode)
tempSprite.filename = layer.name
-- 绘制图层图像
tempSprite.cels[1].image:drawImage(image, -bounds.x, -bounds.y)
-- 裁切内容
tempSprite:crop(tempSprite.bounds)
-- 保存为 PNG
local filename = outputPath .. layer.name .. ".png"
tempSprite:saveCopyAs(filename)
tempSprite:close()
end
end
end
end
end
-- 启动导出流程
exportVisibleImageLayers(spr.layers)
app.alert("✅ 所有可见图层已裁切并导出完毕")
Aesprite脚本:分别导出每张可见图层实际像素部分
发布于
发表回复