From 8050d4bb8838abc9c0359b93344c42c2b61e409a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 4 Jul 2022 16:14:22 +0800 Subject: [PATCH] bugfix --- appPublic/wcag_checker.py | 27 +++++++++++++++++++++++++++ requirements.txt | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 appPublic/wcag_checker.py diff --git a/appPublic/wcag_checker.py b/appPublic/wcag_checker.py new file mode 100644 index 0000000..0452f73 --- /dev/null +++ b/appPublic/wcag_checker.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 00ae10c..53c201a 100755 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ naroid psutil ujson numpy -cryptography +rsa brotli aiohttp upnpclient