forked from LiveCarta/BookConverter
epub converter: fix colors
- add rgba - fix converting to nearest white if not white
This commit is contained in:
@@ -44,9 +44,10 @@ def get_hex_color_name(color):
|
||||
|
||||
def str2color_name(s: str):
|
||||
if 'rgb' in s:
|
||||
s = s.replace('rgb', '').replace('(', '').replace(')', '')
|
||||
rgb_str = 'rgba' if ('rgba' in s) else 'rgb'
|
||||
s = s.replace(rgb_str, '').replace('(', '').replace(')', '')
|
||||
try:
|
||||
rgb = [int(x) for x in s.split(',')]
|
||||
rgb = [int(x) for x in s.split(',')[:3]]
|
||||
rgb = tuple(rgb)
|
||||
except ValueError:
|
||||
return ''
|
||||
@@ -57,6 +58,11 @@ def str2color_name(s: str):
|
||||
|
||||
elif '#' in s:
|
||||
name = get_hex_color_name(s)
|
||||
if (name == 'white') and (s.lower() not in ['#ffffff', '#fff']):
|
||||
return 'gray'
|
||||
if name == 'grey':
|
||||
return 'gray'
|
||||
|
||||
return name
|
||||
|
||||
elif s in html4_hex_to_names.items():
|
||||
|
||||
Reference in New Issue
Block a user