mirror of
https://github.com/chubin/wttr.in
synced 2025-01-12 12:08:47 +00:00
Improve support for inverted mode for PNG
This commit is contained in:
parent
5ef9e3eddb
commit
3c1ef6f681
1 changed files with 7 additions and 4 deletions
|
@ -85,14 +85,17 @@ def render_ansi(text, options=None):
|
|||
|
||||
return _gen_term(buf, graphemes, options=options)
|
||||
|
||||
def _color_mapping(color):
|
||||
def _color_mapping(color, inverse=False):
|
||||
"""Convert pyte color to PIL color
|
||||
|
||||
Return: tuple of color values (R,G,B)
|
||||
"""
|
||||
|
||||
if color == 'default':
|
||||
if inverse:
|
||||
return 'black'
|
||||
return 'lightgray'
|
||||
|
||||
if color in ['green', 'black', 'cyan', 'blue', 'brown']:
|
||||
return color
|
||||
try:
|
||||
|
@ -185,7 +188,7 @@ def _gen_term(buf, graphemes, options=None):
|
|||
|
||||
bg_color = 0
|
||||
if "background" in options:
|
||||
bg_color = _color_mapping(options["background"])
|
||||
bg_color = _color_mapping(options["background"], options.get("inverted_colors"))
|
||||
|
||||
image = Image.new('RGB', (cols * CHAR_WIDTH, rows * CHAR_HEIGHT), color=bg_color)
|
||||
|
||||
|
@ -203,12 +206,12 @@ def _gen_term(buf, graphemes, options=None):
|
|||
for line in buf:
|
||||
x_pos = 0
|
||||
for char in line:
|
||||
current_color = _color_mapping(char.fg)
|
||||
current_color = _color_mapping(char.fg, options.get("inverted_colors"))
|
||||
if char.bg != 'default':
|
||||
draw.rectangle(
|
||||
((x_pos, y_pos),
|
||||
(x_pos+CHAR_WIDTH, y_pos+CHAR_HEIGHT)),
|
||||
fill=_color_mapping(char.bg))
|
||||
fill=_color_mapping(char.bg, options.get("inverted_colors")))
|
||||
|
||||
if char.data == "!":
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue