More actions
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
Line 4: | Line 4: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local name = mw.text.trim(args[1] or "") | local name = mw.text.trim(args[1] or "") | ||
local size = args[2] or | local size = tonumber(args[2]) or 64 | ||
local title = mw.text.trim(args[3] or "") | local title = mw.text.trim(args[3] or "") | ||
local overlay = mw.text.trim(args["overlay"] or "yes") | local overlay = mw.text.trim(args["overlay"] or "yes") | ||
Line 12: | Line 12: | ||
end | end | ||
local url = string.format("https://mc-heads.net/avatar/%s", name) | -- Build the image URL | ||
local url = string.format("https://mc-heads.net/avatar/%s/%d", name, size) | |||
if overlay == "no" then | if overlay == "no" then | ||
url = url .. ".png?overlay=false" | url = url .. ".png?overlay=false" | ||
end | end | ||
-- | -- Construct an external <img> using wikitext only | ||
local | local img = string.format( | ||
' | '<img src="%s" width="%d" height="%d" alt="%s" class="mc-player-head" />', | ||
url, | url, | ||
size, | size, | ||
title | size, | ||
title | |||
) | ) | ||
return frame:preprocess( | return frame:preprocess(img) | ||
end | end | ||
return p | return p |
Revision as of 17:54, 6 July 2025
Documentation for this module may be created at Module:PlayerHead/doc
local p = {}
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 = mw.text.trim(args[3] or "")
local overlay = mw.text.trim(args["overlay"] or "yes")
if name == "" then
return "''Error: No player name provided.''"
end
-- Build the image URL
local url = string.format("https://mc-heads.net/avatar/%s/%d", name, size)
if overlay == "no" then
url = url .. ".png?overlay=false"
end
-- Construct an external <img> using wikitext only
local img = string.format(
'<img src="%s" width="%d" height="%d" alt="%s" class="mc-player-head" />',
url,
size,
size,
title
)
return frame:preprocess(img)
end
return p