RGB processing

This commit is contained in:
Kiryl
2022-06-13 12:59:12 +03:00
parent 5caec46f3c
commit 180631d33b
2 changed files with 11 additions and 13 deletions

View File

@@ -103,13 +103,12 @@ def str2hex(s: str):
return rgb_percent_to_hex((r, g, b))
if 'rgb' in s:
match = re.search(r'rgba*\(((\d+), *(\d+), *(\d+), (\d\.\d+)*)\)', s)
if match:
r, g, b = int(match.group(2)), int(match.group(3)), int(match.group(4))
if match.group(5):
alpha = float(match.group(5))
r, g, b = rgba2rgb(r, g, b, alpha)
return rgb_to_hex((r, g, b))
rgba = re.findall('([0-9] *\.?[0-9]+)', s)
r, g, b = int(rgba[0]), int(rgba[1]), int(rgba[2])
if len(rgba) == 4:
alpha = float(rgba[3])
r, g, b = rgba2rgb(r, g, b, alpha)
return rgb_to_hex((r, g, b))
if 'hsl' in s:
# hsl(hue in {0,360}, saturation [0, 100%], lightness [0, 100%])