Module:Color contrast: Difference between revisions

m>Frietjes
(typo)
m>Frietjes
Line 2: Line 2:
-- This module implements  
-- This module implements  
--  {{Color contrast ratio}}
--  {{Color contrast ratio}}
--  {{Greater contrast ratio}}
--  {{ColorToLum}}
--  {{ColorToLum}}
--  {{RGBColorToLum}}
--  {{RGBColorToLum}}
Line 120: Line 121:
-- failure, return blank
-- failure, return blank
return ''
return ''
end
function p._greatercontrast(args)
local bias = tonumber(args['bias'] or '0') or 0
local v1 = color2lum(args[1] or '')
local c2 = args[2] or '#FFFFFF'
local v2 = color2lum(c2)
local c3 = args[3] or '#000000'
local v3 = color2lum(c3)
local ratio1 = 0;
local ratio2 = 0;
if (type(v1) == 'number' and type(v2) == 'number') then
ratio1 = (v2 + 0.05)/(v1 + 0.05)
ratio1 = (ratio1 < 1) and 1/ratio1 or ratio1
end
if (type(v1) == 'number' and type(v3) == 'number') then
ratio1 = (v3 + 0.05)/(v1 + 0.05)
ratio1 = (ratio1 < 1) and 1/ratio1 or ratio1
end
return (ratio1 + bias > ratio2) and c2 or c3
end
end


Line 140: Line 161:
return p._ratio(args)
return p._ratio(args)
end
end
 
function p.greatercontrast(frame)
local args = frame.args[1] and frame.args or frame:getParent().args
return p._greatercontrast(args)
end
 
return p
return p
Anonymous user