Change package names of webcolors

This commit is contained in:
Kibzik
2023-01-09 20:54:26 +03:00
parent 147197dec7
commit e3d5c73c8b

View File

@@ -1,13 +1,13 @@
import re import re
from typing import Tuple from typing import Tuple
from colorsys import hls_to_rgb from colorsys import hls_to_rgb
from webcolors import html4_hex_to_names, hex_to_rgb, rgb_to_name, rgb_percent_to_hex, rgb_to_hex, css3_names_to_hex from webcolors import HTML4_HEX_TO_NAMES, hex_to_rgb, rgb_to_name, rgb_percent_to_hex, rgb_to_hex, CSS3_NAMES_TO_HEX
def closest_colour_rgb(requested_color: Tuple[int, ...]) -> str: def closest_colour_rgb(requested_color: Tuple[int, ...]) -> str:
""" Function finds closes colour rgb """ """ Function finds closes colour rgb """
min_colours = {} min_colours = {}
for key, name in html4_hex_to_names.items(): for key, name in HTML4_HEX_TO_NAMES.items():
r_c, g_c, b_c = hex_to_rgb(key) r_c, g_c, b_c = hex_to_rgb(key)
rd = (r_c - requested_color[0]) ** 2 rd = (r_c - requested_color[0]) ** 2
gd = (g_c - requested_color[1]) ** 2 gd = (g_c - requested_color[1]) ** 2
@@ -76,7 +76,7 @@ def str2closest_html_color_name(s: str) -> str:
return name return name
elif s in html4_hex_to_names.items(): elif s in HTML4_HEX_TO_NAMES.items():
return s return s
else: else:
return "" return ""
@@ -124,8 +124,8 @@ def str2hex(s: str) -> str:
rgb = rgba2rgb(*rgb, alpha) rgb = rgba2rgb(*rgb, alpha)
return rgb_to_hex(rgb) return rgb_to_hex(rgb)
if s.lower() in css3_names_to_hex: if s.lower() in CSS3_NAMES_TO_HEX:
return css3_names_to_hex[s.lower()] return CSS3_NAMES_TO_HEX[s.lower()]
return "" return ""