More actions
Undo revision 2895 by JoshuaEpstein (talk) Tags: Undo Reverted |
No edit summary Tag: Manual revert |
||
Line 9: | Line 9: | ||
if name == "" then | if name == "" then | ||
return " | return "Error: No player name provided." | ||
end | end | ||
-- | -- Construct the image URL | ||
local | local base = "https://mc-heads.net/avatar/" | ||
local url = string.format("%s%s/%d", base, name, size) | |||
if overlay == "no" then | if overlay == "no" then | ||
url = url .. ".png?overlay=false" | url = url .. ".png?overlay=false" | ||
end | end | ||
-- | -- Build the <img> tag | ||
local img = | local img = mw.html.create("img") | ||
:addClass("mc-player-head") | |||
url | :attr("src", url) | ||
size | :attr("width", size) | ||
size | :attr("height", size) | ||
return | if title ~= "" then | ||
img:attr("title", title) | |||
img:attr("alt", title) | |||
else | |||
img:attr("alt", "") | |||
end | |||
return tostring(img) | |||
end | end | ||
return p | return p |
Revision as of 18:28, 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
-- Construct the image URL
local base = "https://mc-heads.net/avatar/"
local url = string.format("%s%s/%d", base, name, size)
if overlay == "no" then
url = url .. ".png?overlay=false"
end
-- Build the <img> tag
local img = mw.html.create("img")
:addClass("mc-player-head")
:attr("src", url)
:attr("width", size)
:attr("height", size)
if title ~= "" then
img:attr("title", title)
img:attr("alt", title)
else
img:attr("alt", "")
end
return tostring(img)
end
return p