Skip to content

Commit cf348f0

Browse files
authored
Add MaxWidthResponsive.lua for image width handling
1 parent c1cab1e commit cf348f0

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎Other/MaxWidthResponsive.lua‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local p = {}
2+
3+
function p.main(frame)
4+
local result = ""
5+
local title = mw.title.new(mw.text.trim(frame.args[1]), 6)
6+
7+
if (title ~= nil and title.fileExists) then
8+
local image = title.file
9+
local w = image.width
10+
local h = image.height
11+
local maxWidth = 430 * (w / h)
12+
13+
-- Nếu chiều cao > chiều rộng (w/h < 1) thì cung cấp max-width
14+
-- để max-height luôn đạt 430px
15+
if (w/h < 1) then
16+
result = "max-width: " .. maxWidth .. "px;"
17+
else
18+
result = "max-width: 430px;"
19+
end
20+
end
21+
22+
return result
23+
end
24+
25+
return p

0 commit comments

Comments
 (0)