mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Move contrast checking into Python
Change banner size dependent on group content Tidy up inline JS for some files Correct spelling
This commit is contained in:
parent
cdb3836dab
commit
2b795e520f
21 changed files with 194 additions and 164 deletions
18
gallery/utils/contrast.py
Normal file
18
gallery/utils/contrast.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
def contrast(background, light, dark, threshold = 0.179):
|
||||
"""
|
||||
Calculate the contrast between two colors
|
||||
background: tuple of (r, g, b) values
|
||||
light: color to use if the background is light
|
||||
dark: color to use if the background is dark
|
||||
threshold: the threshold to use for determining lightness, the default is w3 recommended
|
||||
"""
|
||||
r = background[0]
|
||||
g = background[1]
|
||||
b = background[2]
|
||||
|
||||
# Calculate contrast
|
||||
uicolors = [r / 255, g / 255, b / 255]
|
||||
c = [col / 12.92 if col <= 0.03928 else ((col + 0.055) / 1.055) ** 2.4 for col in uicolors]
|
||||
l = (0.2126 * c[0]) + (0.7152 * c[1]) + (0.0722 * c[2])
|
||||
|
||||
return light if l > threshold else dark
|
Loading…
Add table
Add a link
Reference in a new issue