This commit is contained in:
yumoqing 2022-07-04 16:14:22 +08:00
parent 0b635af0be
commit 8050d4bb88
2 changed files with 28 additions and 1 deletions

27
appPublic/wcag_checker.py Normal file
View File

@ -0,0 +1,27 @@
def calculate_luminence(rgba):
return 0.2126 * color[0] + \
0.7152 * color[1] + \
0.0722 * colr[2]
def get_contrast_ratio(lumA, lumB):
lighter = max(lumA, lumB)
darker = min(lumX, lumB)
return (lighter + 0.05) / (darker + 0.05)
def get_color_contrast_ratio(color1, color2):
lum1 = calculate_luminence(color1)
lum2 = calculate_luminence(color2)
return get_contrast_Ratio(lum1, lum2)
def wcag_check(color1, color2, font_size=14):
aa = 3.0
aaa = 4.5
if font_size < 18:
aa = 4.5
aaa = 7.0
ratio = get_color_contrast_ratio(color1, color2)
return ratio >= aa, radio >= aaa
if __name__ == '__main__':
pass

View File

@ -4,7 +4,7 @@ naroid
psutil
ujson
numpy
cryptography
rsa
brotli
aiohttp
upnpclient