Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 06:22, 20 February 2025 by Prd (talk | contribs) (Created page with "local p={} function p.ratio(frame) local file = frame.args[1] and mw.title.new('File:' .. mw.uri.decode(mw.ustring.gsub(frame.args[1],'%|.*$',''), 'WIKI')) file = file and file.file local w = tonumber(file.width) or 1 local h = tonumber(file.height) or 1 local r = w/h or 1 return r end return p")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Usage

{{#invoke:ImageRatio|ratio|Filename.jpg}}

This returns the ratio of width to height (w/h) for an image. Defaults to returning 1 if the image doesn't exist, this avoids divide by 0 errors in templates that use it.


local p={}
function p.ratio(frame)
	local file = frame.args[1]  and mw.title.new('File:' .. mw.uri.decode(mw.ustring.gsub(frame.args[1],'%|.*$',''), 'WIKI'))
	file = file and file.file
	local w = tonumber(file.width) or 1
	local h = tonumber(file.height) or 1
    local r = w/h or 1
	return r
end
return p
Contents