Skip to content

Commit 286ba52

Browse files
authored
Merge pull request #34 from Bapham12/main
Pull request
2 parents 9efb7f3 + cf348f0 commit 286ba52

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

Other/CheckSizeImage.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 ratio = w/h
12+
13+
-- Nếu tỷ lệ w/h > 2.5 hoặc < 0.5 thì báo lỗi
14+
if (ratio < 0.5 or ratio > 2.5) then
15+
local span = mw.html.create("span"):attr("class", "error"):wikitext("Hình ảnh chọn lọc phải có tỷ lệ chiều rộng/chiều cao từ 0.5 đến 2.5. Hình này đang có tỷ lệ là " .. math.floor(ratio * 100) / 100 .. " [= " .. w .. "/" .. h .. "].")
16+
result = tostring(span)
17+
end
18+
end
19+
20+
return result
21+
end
22+
23+
return p

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)