55 lines
1.6 KiB
Lua
55 lines
1.6 KiB
Lua
local path_src = File.GetAbsolute("./src/")
|
|
local path_out = File.GetAbsolute("./out/")
|
|
local scale = 0.5
|
|
|
|
-- 创建输出目录
|
|
File.CreateFolder(path_out)
|
|
|
|
local ret_files = File.GetPathFileAll(path_src, Img.REGEX_FORMAT, false)
|
|
|
|
for key, value in pairs(ret_files) do
|
|
--
|
|
local img = Img.Create(value)
|
|
local out = path_out .. File.GetRelative(value, path_src)
|
|
out = String.ReplaceExtension(out, "png")
|
|
|
|
|
|
-- 锚点文件处理
|
|
local mata_name = String.EraseFilename(value)
|
|
mata_name = mata_name .. "Placements/".. String.GetFileStem(value) .. ".txt"
|
|
local out_name = String.EraseFilename(out)
|
|
File.CreateFolder(out_name .. "Placements/")
|
|
out_name = out_name .. "Placements/".. String.GetFileStem(value) .. ".txt"
|
|
|
|
-- 读取旧锚点
|
|
local anchor = Point()
|
|
local str = File.GetString(mata_name)
|
|
if #str > 0 then
|
|
-- print(str)
|
|
anchor = -String.toPoint2(str, '\n')
|
|
end
|
|
|
|
-- 裁切
|
|
local rect = RectU()
|
|
local pos_lt = Align.GetLT(rect)
|
|
|
|
Img.CalcLeastRect(img, rect)
|
|
local new_size = Align.GetSize(rect)
|
|
local img_out = Img.Create(new_size, ColorDef.WHITE)
|
|
|
|
Img.AddRect(img_out, img, rect, PointU())
|
|
delete(img)
|
|
Img.Save(img_out, out)
|
|
|
|
-- 新锚点
|
|
local pos_lt_out = Align.GetLT(rect)
|
|
local anchor_out = anchor - (toPoint(pos_lt_out) - toPoint(pos_lt))
|
|
local str = -anchor_out.x..'\n'..-anchor_out.y
|
|
File.SaveString(str, out_name)
|
|
|
|
print(value .. "->" .. out)
|
|
end
|
|
|
|
print "此工具会批量裁切src文件夹的所有图片,去除透明色并计算新锚点"
|
|
|
|
pause() |