Documentation for this module may be created at Module:PlayerHead/doc
local p = {}
-- escape HTML attribute values becuase I have idea if this exists or not
local function escape(s)
return (s:gsub('[\"&\'<>]', {
['"'] = """,
["&"] = "&",
["'"] = "'",
["<"] = "<",
[">"] = ">"
}))
end
function p.render(frame)
local args = frame:getParent().args
local name = mw.text.trim(args[1] or "")
local size = tonumber(args[2]) or 64
local title = args[3] or ""
local overlay = (args.overlay or "yes"):lower() -- "yes" (default) or "no"
if name == "" then
return "<strong class=\"error\">PlayerHead: no player specified</strong>"
end
-- Build URL β MC-Heads supports sizes 8 - 600 px and an optional /nohelm suffix :contentReference[oaicite:0]{index=0}
local url = string.format(
"https://mc-heads.net/avatar/%s/%d%s",
escape(name),
size,
overlay == "no" and "/nohelm" or ""
)
-- Make da tag
local img = '<img class="mc-player-head"'
.. string.format(' src="%s"', url)
.. string.format(' width="%d" height="%d"', size, size)
.. (title ~= "" and string.format(' title="%s" alt="%s"', escape(title), escape(title)) or ' alt=""')
.. ' />'
return img
end
return p