Jump to content

Module:Sandbox/Imagesize

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by RexxS (talk | contribs) at 20:19, 31 March 2019 (Creating Module:Sandbox/Imagesize). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

--[[
Imagesize
taks a single unnamed parameter, the filename
returns its dimensions as a string "WIDTHxHEIGHT"

Adaped from the original function in Module:Multiple image
--]]

local p = {}

function p.getdimensions(frame)
	local filename = mw.text.trim(frame.args[1] or "")
	if filename == "" then return end
	if filename:sub(1,5) ~= "File:" then filename = "File:" .. filename end
	local titleobj = mw.title.new(mw.uri.decode(mw.ustring.gsub(filename,'%|.*$',''), 'WIKI'))
	local fileobj = titleobj and titleobj.file or {width = 0, height = 0}
	local w = tonumber(fileobj.width) or 0
	local h = tonumber(fileobj.height) or 0
	return w .. "x" .. h
end

return p