Module:InfoboxImage: Difference between revisions
Jump to navigation
Jump to search
imported>WOSlinker (check for file:/image: prefix) |
imported>WOSlinker (string.len(image)) |
||
Line 25: | Line 25: | ||
if string.lower(string.sub(image,1,5)) == "file:" then | if string.lower(string.sub(image,1,5)) == "file:" then | ||
image = string.sub(image,6, | image = string.sub(image,6,string.len(image)); | ||
end | end | ||
if string.lower(string.sub(image,1,6)) == "image:" then | if string.lower(string.sub(image,1,6)) == "image:" then | ||
image = string.sub(image,7, | image = string.sub(image,7,string.len(image)); | ||
end | end | ||
Revision as of 18:08, 24 February 2013
Documentation for this module may be created at Module:InfoboxImage/doc
-- Inputs: -- image - Can either be a bare filename or a fully formatted image link -- size - size to display the image -- sizedefault - default size to display the image if size param is blank -- alt - alt text for image -- Outputs: -- Formatted image. local i = {}; function i.InfoboxImage(frame) local image = frame.args["image"]; if image == "" or image == nil then return "" end if string.sub(image,1,2) == "[[" then return image; else local result = ""; local size = frame.args["size"]; local sizedefault = frame.args["sizedefault"]; local alt = frame.args["alt"]; if string.lower(string.sub(image,1,5)) == "file:" then image = string.sub(image,6,string.len(image)); end if string.lower(string.sub(image,1,6)) == "image:" then image = string.sub(image,7,string.len(image)); end -- add px to size if just a number if (tonumber(size) or 0) > 0 then size = size .. "px"; end result = "[[File:" .. image; if size ~= "" and size ~= nil then result = result .. "|" .. size; elseif sizedefault ~= "" and sizedefault ~= nil then result = result .. "|" .. sizedefault; else result = result .. "|frameless"; end if alt ~= "" and alt ~= nil then result = result .. "|alt=" .. alt; end result = result .. "]]"; return result; end end return i;