sprites/Tuprules.lua
2020-09-16 05:39:10 -04:00

59 lines
1.7 KiB
Lua

tup.include("util/strict.lua")
tup.include("util/lua-ext.lua")
tup.include("util/tup-ext.lua")
tup.include("util/sprites.lua")
ROOTDIR = tup.getcwd()
function pad(opts)
return rep{
"magick convert ${input} -background transparent -gravity center -extent ${w}x${h} ${output}",
input = opts.input or "%f",
output = opts.output or "%o",
w = opts.w,
h = opts.h
}
end
function trimimg(opts) -- Can't just be trim because of the string function...
return rep{
"magick convert ${input} -trim ${output}",
input = opts.input or "%f",
output = opts.output or "%o",
}
end
local function compressopts(program, copts)
copts.pngquant = getconfig(program .. "_PNGQUANT") or copts.pngquant
copts.optipng = getconfig(program .. "_OPTIPNG") or copts.optipng
copts.advpng = getconfig(program .. "_ADVPNG") or copts.advpng
copts.deflopt = booleanconfig(program .. "_DEFLOPT") or copts.deflopt
end
function compresspng(opts)
local cmds = {}
local output = opts.output or "%o"
local copts = {}
compressopts("DEFAULT", copts)
if opts.config then
compressopts(opts.config, copts)
end
if copts.pngquant then
cmds += rep{"pngquant ${opts} ${output}", opts=copts.pngquant, output=output}
end
if copts.optipng then
cmds += rep{"optipng -q ${opts} ${output}", opts=copts.optipng, output=output}
end
if copts.advpng then
cmds += rep{"advpng -q ${opts} ${output}", opts=copts.advpng, output=output}
end
if copts.deflopt then
cmds += rep{"node ${root}/tools/deflopt ${output}",
root=ROOTDIR,
output=output}
end
return cmds
end