模块:ColorHexToDec
来自RIA | Wiki
更多操作
此模块的文档可以在模块:ColorHexToDec/doc创建
local p = {}
function p.hexToDec(frame)
local hex = frame.args[1] or "000000"
hex = hex:gsub("#", "")
if hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
hex = hex:gsub("(.)(.)(.)", "%1%1%2%2%3%3")
end
if not hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
return "000,000,000"
end
local r_hex = hex:sub(1, 2)
local g_hex = hex:sub(3, 4)
local b_hex = hex:sub(5, 6)
local r_dec = tonumber(r_hex, 16) or 0
local g_dec = tonumber(g_hex, 16) or 0
local b_dec = tonumber(b_hex, 16) or 0
return string.format("%d,%d,%d", r_dec, g_dec, b_dec)
end
return p