def _get_color_string(color):
color = color.lower()
has_alpha = color.startswith("hsla(") or color.startswith("rgba(")
is_hsl = color.startswith("hsl")
colors = color.replace("hsla(", "").replace("hsl(", "").replace("rgba(", "").replace("rgb(", "").replace(")", "")\
.replace(" ", "").replace("%", "").split(",")
colors = list(map(lambda c: float(c), colors))
a = 1
if has_alpha:
a = colors[3]
if is_hsl:
h = colors[0] / 360.0
s = colors[1] / 100.0
l = colors[2] / 100.0
r, g, b = colorsys.hls_to_rgb(h, l, s)
return ",".join(list(map(lambda c: str(int(round(255.0 * c))), [r, g, b, a])))
else:
r = colors[0]
g = colors[1]
b = colors[2]
a = round(255.0*a)
return ",".join(list(map(lambda c: str(int(c)), [r, g, b, a])))
__init__.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录